Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DON'T MERGE] Improving Freighter developer docs #1513

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
4edcb81
adds fetchJson to handle non json fetch responses
aristidesstaffieri Aug 27, 2024
599e250
awaits json response
aristidesstaffieri Aug 27, 2024
b5496c9
encodes xdr for query param usage
aristidesstaffieri Aug 27, 2024
9b758db
[FEATURE] malicious tx warning, sign-tx (#1449)
aristidesstaffieri Aug 28, 2024
786cbb5
adds scan labels for all scan result types, tweaks styles
aristidesstaffieri Aug 28, 2024
6e2ccdf
Added translations
aristidesstaffieri Aug 28, 2024
bf43b10
adds unit tests for grant access views scan site labels
aristidesstaffieri Aug 29, 2024
1fe440b
adds sac contract check in transfer detail, formats transfers like re…
aristidesstaffieri Aug 28, 2024
f22832c
adds unit test for sac transfer history item
aristidesstaffieri Aug 29, 2024
3c58b8f
memoizes translation fn as dependency of history item effect
aristidesstaffieri Aug 29, 2024
8f2dd57
Feature/blockaid asset UI warning (#1452)
piyalbasu Aug 30, 2024
e660533
removes configurable fee constraint on token transfers
aristidesstaffieri Aug 30, 2024
df27b1d
take into account min resource fee for toke payments
aristidesstaffieri Sep 3, 2024
af176f8
split out simulation api to internal api, update tests to use correct…
aristidesstaffieri Sep 3, 2024
6aceb69
qa fixes for blockaid asset check (#1460)
piyalbasu Sep 3, 2024
7f107b1
add Blockaid tests for account, manage assets, send and swap flows (#…
piyalbasu Sep 3, 2024
97cce0e
adds tx scan during send payment flow tx details
aristidesstaffieri Sep 4, 2024
7ebf035
adds failed simulation state to tx scan label, updates tx scan respon…
aristidesstaffieri Sep 5, 2024
bc6c91f
removes unused cast functions
aristidesstaffieri Sep 5, 2024
2fa6312
add Blockaid announcement modal (#1465)
piyalbasu Sep 5, 2024
782f5ab
split tx scan for classic sends and swaps
aristidesstaffieri Sep 5, 2024
b376fe4
pulls tx construction out into helper
aristidesstaffieri Sep 5, 2024
d53346f
Bugfix/show non malicious blockaid info (#1469)
piyalbasu Sep 9, 2024
d38d80f
fixes transparent bg on asset warning
aristidesstaffieri Sep 9, 2024
046567f
handle complete blockaid data fro indexer (#1474)
piyalbasu Sep 9, 2024
616d03d
add better typing for standalone balances (#1475)
piyalbasu Sep 11, 2024
f3c4591
Merge branch 'master' into release/5.23.2
piyalbasu Sep 11, 2024
98b7097
add blockaid scan for custom mainnet and use blockaid lib for types (…
piyalbasu Sep 12, 2024
3235067
makes suspicious asset check stricter
aristidesstaffieri Sep 16, 2024
c14b687
use blockaid lib for blockaid scan tx result (#1480)
piyalbasu Sep 16, 2024
f3809c3
move terser to only production config (#1481)
piyalbasu Sep 16, 2024
89f7637
check for scam asset warning message in send flow (#1482)
piyalbasu Sep 16, 2024
ab4feef
Feature/rm stellar.expert safety checks (#1483)
piyalbasu Sep 17, 2024
15493bc
adds advanced settings guide
aristidesstaffieri Sep 13, 2024
4318b2d
adds add asset docs
aristidesstaffieri Sep 13, 2024
f63ba20
adds docs for account, network settings, make payment, add asset, and…
aristidesstaffieri Sep 16, 2024
38b47d9
fix grammar
aristidesstaffieri Sep 17, 2024
f854edc
fix typo
aristidesstaffieri Sep 17, 2024
1c88d19
fix grammar
aristidesstaffieri Sep 17, 2024
46e99a7
fix grammar
aristidesstaffieri Sep 17, 2024
9cb2303
fix grammar
aristidesstaffieri Sep 17, 2024
0bc9127
splits guide into 2 groups, updates copy importing new key instructions
aristidesstaffieri Sep 17, 2024
20498a8
split intro in sidebar, expand intro to include new docs
aristidesstaffieri Sep 17, 2024
6cadcea
clarify seed phrase import copy
aristidesstaffieri Sep 17, 2024
ba9227d
rename "blocked accounts" to "memo required accounts" (#1485)
piyalbasu Sep 19, 2024
1d98378
removes benign scan label for site scans
aristidesstaffieri Sep 19, 2024
8347a9b
skip benign label test for now
aristidesstaffieri Sep 19, 2024
f6daddf
updates tx scan copy and adds malicious tx scan state for buttons
aristidesstaffieri Sep 19, 2024
3bdea09
tweaks grant access width to stop button overflow, tweaks cancel text
aristidesstaffieri Sep 24, 2024
a87938d
better loading states while loading blockaid data (#1486)
piyalbasu Sep 24, 2024
3780072
adjust blockaid-related styling (#1493)
piyalbasu Sep 24, 2024
c7e50b7
scan search results in a loop to avoid long loading times (#1494)
piyalbasu Sep 25, 2024
8dead38
scan asset results in manual add (#1496)
piyalbasu Sep 26, 2024
4257248
add helper to determine if a tx is suspicious (#1497)
piyalbasu Sep 26, 2024
97268da
show error button in send flow warning (#1499)
piyalbasu Sep 26, 2024
6131cf6
restore dropped styles for modal subject
aristidesstaffieri Sep 27, 2024
d8560f5
redesign popup blockaid warnings (#1503)
piyalbasu Oct 2, 2024
2128740
adjust padding on buttons (#1504)
piyalbasu Oct 3, 2024
b3225d2
adds new test token address after testnet reset
aristidesstaffieri Oct 3, 2024
b4afa73
comments blockaid announcement, tweaks e2e details in tests
aristidesstaffieri Oct 3, 2024
adc1f85
fixes loading state for token transfer details after transfer, fixes …
aristidesstaffieri Oct 4, 2024
c06e75f
updates test for history item change
aristidesstaffieri Oct 4, 2024
4b9157c
fix stale state instead by manually dismissing loading when not scann…
aristidesstaffieri Oct 4, 2024
010b458
restore login and fund on first payment test
aristidesstaffieri Oct 4, 2024
41f3199
make e2e tests run in sequence
aristidesstaffieri Oct 4, 2024
4f78900
restore slow timeout settings for payment tests
aristidesstaffieri Oct 4, 2024
0df7282
avoids rescanning classic transactions after tx is sent in details
aristidesstaffieri Oct 4, 2024
ad93929
add explicit prop to scan tx in tx details
aristidesstaffieri Oct 4, 2024
3de389c
make sure to show sim errors in send flow; add tests (#1506)
piyalbasu Oct 7, 2024
6587274
Fix flakey tests (#1509)
piyalbasu Oct 8, 2024
2e6a2fd
adds account creator base tests
aristidesstaffieri Oct 3, 2024
2fa9477
adds success flow test for account creator
aristidesstaffieri Oct 7, 2024
45a9c40
Merge commit '9a1962ed25d34cea9f1e3d5cb64bf0e5804a08de' into release/…
piyalbasu Oct 8, 2024
c2ace4a
add some tips for working with Soroban
piyalbasu Oct 8, 2024
5299bcf
updating some copy
piyalbasu Oct 8, 2024
caa1031
adding third party integration docs
piyalbasu Oct 8, 2024
48c0545
Merge commit '5c629992177dd98cf385c645822488362bd50d2a' into docs/sor…
piyalbasu Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions @shared/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"@blockaid/client": "^0.28.0",
"@blockaid/client": "^0.25.0",
"@stellar/js-xdr": "^3.1.1",
"bignumber.js": "^9.1.1",
"prettier": "^2.0.5",
"stellar-sdk": "yarn:@stellar/stellar-sdk@13.0.0-beta.1",
"stellar-sdk-next": "yarn:@stellar/stellar-sdk@13.0.0-beta.1",
"stellar-sdk": "yarn:stellar-sdk@^12.1.0",
"stellar-sdk-next": "yarn:stellar-sdk@^12.1.0",
"typescript": "~3.7.2",
"webextension-polyfill": "^0.12.0"
},
Expand Down
7 changes: 7 additions & 0 deletions @shared/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ export interface Balance {
}

export type BlockAidScanAssetResult = Blockaid.TokenScanResponse;
export interface BlockAidScanAssetResultIndex {
[key: string]: Blockaid.TokenScanResponse.AttackTypes &
Blockaid.TokenScanResponse.Fees &
Blockaid.TokenScanResponse.BasicMetadataToken &
Blockaid.TokenScanResponse.FinancialStats &
Blockaid.TokenScanResponse.TradingLimits;
}

export type BlockAidScanSiteResult = Blockaid.SiteScanResponse;
export type BlockAidScanTxResult = Blockaid.StellarTransactionScanResponse;
Expand Down
149 changes: 149 additions & 0 deletions docs/docs/guide/developingForSoroban.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
---
id: developingForSoroban
title: Developing A Wallet For Soroban
---

Freighter offers first-class support for Soroban, but developing a wallet that supports a new smart contract platform came with many learnings. Below you will find some tips for developing a wallet that takes advantage of the full capabilities of Soroban.

### Common Scenarios

When interacting with a Soroban smart contract from a wallet, you will need to be able to encode human readable values into smart contract (SC) values and vice-versa.

For example, consider the common use-case of sending a token payment. You would likely need to take in some values that a user configures in form fields and convert those into SC values to generate an XDR to simulate.

Another common use-case is signing arbitrary XDR's sent from a dapp. In this scenario, you'll want to be dig into the invocations being called by a Soroban XDR and show them to the user in a way that they can understand what they're signing.

We'll go through each of these scenarios below.

### Encoding SC Values

In Freighter, we do this by utilizing helper methods in `@stellar/stellar-sdk`.

The below example is an abridged version of what Freighter does under the hood when it initiates a token transfer. It is designed for a token transfer invocation, but this approach would work for any smart contract invocation.

```javascript

import {
Address,
Contract,
TransactionBuilder,
Memo,
SorobanRpc,
TransactionBuilder,
XdrLargeInt,
} from "stellar-sdk";

/* For this example, we are assuming the token adheres to the interface documented in SEP-0041 */
const generateTransferXdr =
(contractId, serverUrl, publicKey, destination, amount, fee, networkPassphrase, memo) => {
// the contract id of the the token
const contract = new Contract(contractId);

const server = new SorobanRpc.Server(serverUrl);
const sourceAccount = await server.getAccount(publicKey);
const builder = new TransactionBuilder(sourceAccount, {
fee,
networkPassphrase,
});

// these values would be entered by the user
// we will use some helper methods to convert the addresses and the amount into SC vals
const transferParams = [
new Address(publicKey).toScVal(), // from
new Address(destination).toScVal(), // to
new XdrLargeInt("i128", amount).toI128(), // amount
];

// call the `transfer` method with the listed params
const transaction = builder
.addOperation(contract.call("transfer", ...transferParams))
.setTimeout(180);

if (memo) {
transaction.addMemo(Memo.text(memo));
}

transaction.build();

// simulate the transaction
const simulationTransaction = await server.simulateTransaction(
transaction,
);

// and now assemble the transaction before signing
const preparedTransaction = SorobanRpc.assembleTransaction(
transaction,
simulationTransaction,
)
.build()
.toXDR();

return {
simulationTransaction,
preparedTransaction,
};
}
```

### Walking the invocation tree and parsing SC Values

If you have an XDR of a transaction containing an invocation, you may want to show the contents to the user. We'll walk the whole invocation tree to show the user all the invocations they are authorizing by signing. This is important as invocations can contain subinvocations that the user may not expect. This is an abridged version of what Freighter does when signing an XDR from a dapp.

```javascript
const walkAndParse = (transactionXdr, networkPassphrase) => {
const transaction = TransactionBuilder.fromXDR(
transactionXdr,
networkPassphrase
);

// for this simple example, let's just grab the first operation's first auth entry
const op = transaction.operations[0];
const firstAuthEntry = op.auth[0];

const rootInvocation = firstAuthEntry.rootInvocation();

/* This is a generic example of how to grab the function name, contract id, and the parameters of the
invocation. This is useful for showing a user some details about the function that is actually going to
be called by the smart contract */
const getInvocationArgs = (invocation) => {
const fn = invocation.function();
const _invocation = fn.contractFn();
const contractId = StrKey.encodeContract(
_invocation.contractAddress().contractId()
);

const fnName = _invocation.functionName().toString();
const args = _invocation.args();

return { fnName, contractId, args };
};

const invocations = [];

/* We'll recursively walk the invocation tree to get all of the sub-invocations and pull out the
function name, contractId, and args, as shown above */

walkInvocationTree(rootInvocation, (inv) => {
const args = getInvocationArgs(inv);
if (args) {
invocations.push(args);
}

return null;
});

/* We now have some each information about the root invocation and its subinvocations,
but all the data is in SC val format, so it is still unreadable for users */

// For simplicity, let's just grab the first invocation and show how to parse it
const firstInvocation = invocations[0];
const firstInvocationArgs = firstInvocation.args;

/* Generally, we can just use `scValToNative` to decode a SC val into a usable JS data type
but this may not work for all SC vals.
For more information check the function scValByType in extension/src/popup/helpers/soroban.ts */
const humanReadableArgs = firstInvocationArgs.map((a) => scValToNative(a));

return humanReadableArgs;
};
```
11 changes: 11 additions & 0 deletions docs/docs/guide/thirdPartyIntegration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
id: thirdPartyIntegration
title: Third Party Integration
---

Freighter connects to some third party services to provide a better user experience. As an open source project, we document how we have done this so other wallet developers can similary integrate with services in the ecosystem.

### Integrations

- [Soroswap](https://github.com/stellar/freighter/blob/master/extension/INTEGRATING_SOROSWAP.MD)
- [Hardware Wallets](https://github.com/stellar/freighter/blob/master/extension/INTEGRATING_HARDWARE_WALLET.MD)
7 changes: 6 additions & 1 deletion docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ const userGuidePaths = [
"makePayment",
"signXdr",
];
const techGuidePaths = ["usingFreighterWebApp", "usingFreighterBrowser"];
const techGuidePaths = [
"usingFreighterWebApp",
"usingFreighterBrowser",
"developingForSoroban",
"thirdPartyIntegration",
];

const constructPaths = (paths, basePath) =>
paths.map((path) => `${basePath}/${path}`);
Expand Down
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@
"stellar-sdk>stellar-base>sodium-native": false
}
}
}
}
19 changes: 5 additions & 14 deletions extension/public/static/manifest/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@
},
"background": {
"service_worker": "background.min.js",
"scripts": [
"background.min.js"
]
"scripts": ["background.min.js"]
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"contentScript.min.js"
],
"matches": ["<all_urls>"],
"js": ["contentScript.min.js"],
"run_at": "document_start"
}
],
Expand All @@ -40,9 +34,6 @@
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"permissions": [
"storage",
"alarms"
],
"permissions": ["storage", "alarms"],
"manifest_version": 3
}
}
Loading
Loading