@concordium/browser-wallet-api-helpers 0.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ ## 2.0.0
4
+
5
+ ### Added
6
+
7
+ - Entrypoint to suggest CIS-2 tokens to be added to the connected account's view.
8
+
9
+ ### (Breaking) Changed
10
+
11
+ - Updated web-sdk to version 3, which changes field names in some transaction payloads for sendTransaction entrypoint.
12
+
13
+ ## 1.0.0
14
+
15
+ ### Changed
16
+
17
+ - Fixed broken link + typos in README
18
+ - Removed parameters from smart contract types' payloads, due the wallet ignoring it in favor of separate arguments.
19
+
20
+ ## 0.2.0
21
+
22
+ ### Added
23
+
24
+ - Expose a JSON-RPC client, using the wallet's current JSON-RPC server.
25
+ - `getMostRecentlySelectedAccount` method. This method allows dApps to get the most prioritized account without using `connect`. In a future release it will be updated to actually return the most recently selected account.
26
+
27
+ ### (Breaking) Changed
28
+
29
+ - Updated API of sendTransaction and signMessage to require the account address.
30
+ - Updated API to include an 'accountDisconnected' event.
31
+
32
+ ## 0.1.1
33
+
34
+ - sendTransaction can now take a 5th argument, which is the schema's version. This will allow V1 contract parameters to be serialized.
35
+
36
+ ## 0.1.0
37
+
38
+ - Initialized from the old browser-wallet-api-types package.
39
+ - Added method for detecting the injected Concordium browser wallet API.
package/README.md CHANGED
@@ -8,7 +8,7 @@ The actual implementation of the wallet API can be found in the [in the Concordi
8
8
 
9
9
  ### Installing
10
10
 
11
- See [installing](../../README.md#installing) in repository root.
11
+ See [installing](https://github.com/Concordium/concordium-browser-wallet/blob/main/README.md#installing) in repository root.
12
12
 
13
13
  ### Building
14
14
 
@@ -51,18 +51,18 @@ declare global {
51
51
 
52
52
  ### connect
53
53
 
54
- To request a connection to the wallet from the user, the `connect` method has to be invoked. The method returns a `Promise` resolving with information related to the most recently selected account, which has whitelisted the dApp, or rejecting if the request is rejected in the wallet.
54
+ To request a connection to the wallet from the user, the `connect` method has to be invoked. The method returns a `Promise` resolving with information related to the most recently selected account, which has whitelisted the dApp, or rejecting if the request is rejected in the wallet. If the wallet is locked, then this call prompts the user to first unlock the wallet before accepting or rejecting the connection request.
55
55
 
56
56
  ```typescript
57
57
  const provider = await detectConcordiumProvider();
58
58
  const accountAddress = await provider.connect();
59
59
  ```
60
60
 
61
- N.B. In the current version, if the dApp is already whitelisted, but not by the currently selected account, the returned account will not actually be the most recently selected account, but instead the oldest account that has whitelasted the dApp.
61
+ N.B. In the current version, if the dApp is already whitelisted, but not by the currently selected account, the returned account will not actually be the most recently selected account, but instead the oldest account that has whitelisted the dApp.
62
62
 
63
63
  ### getMostRecentlySelectedAccount
64
64
 
65
- To get the most recently selected account, or to check whether the wallet is connected without using connect, the `getMostRecentlySelectedAccount` can be invoked. The method returns a `Promise` resolving with the address of the most recently selected account in the wallet, or with undefined if there are no connected accounts in the wallet.
65
+ To get the most recently selected account, or to check whether the wallet is connected without using connect, the `getMostRecentlySelectedAccount` can be invoked. The method returns a `Promise` resolving with the address of the most recently selected account in the wallet, or with undefined if the wallet is locked or there are no connected accounts in the wallet.
66
66
 
67
67
  ```typescript
68
68
  const provider = await detectConcordiumProvider();
@@ -74,13 +74,13 @@ if (accountAddress) {
74
74
  }
75
75
  ```
76
76
 
77
- N.B. In the current version, if the currently selected account has not whitelisted the dApp, the returned account will not actually be the most recently selected account, but instead the oldest account that has whitelasted the dApp.
77
+ N.B. In the current version, if the currently selected account has not whitelisted the dApp, the returned account will not actually be the most recently selected account, but instead the oldest account that has whitelisted the dApp.
78
78
 
79
79
  ### sendTransaction
80
80
 
81
81
  To send a transaction, three arguments need to be provided: The account address for the account in the wallet that should sign the transaction, a transaction type and a corresponding payload. Invoking `sendTransaction` returns a `Promise`, which resolves with the transaction hash for the submitted transaction.
82
82
 
83
- If you have not connected with the wallet (or previously been whitelisted) or if the user rejects signing the transaction, the `Promise` will reject.
83
+ If the wallet is locked, or you have not connected with the wallet (or previously been whitelisted) or if the user rejects signing the transaction, the `Promise` will reject.
84
84
 
85
85
  The following exemplifies how to create a simple transfer of funds from one account to another. Please note that [@concordium/web-sdk](https://github.com/Concordium/concordium-node-sdk-js/tree/main/packages/web) is used to provide the correct formats and types for the transaction payload.
86
86
 
@@ -124,7 +124,7 @@ const txHash = await provider.sendTransaction(
124
124
 
125
125
  It is possible to sign arbitrary messages using the keys for an account stored in the wallet, by invoking the `signMessage` method. The first parameter is the account to be used for signing the message. This method returns a `Promise` resolving with a signature of the message.
126
126
 
127
- If you have not connected with the wallet (or previously been whitelisted) or if the user rejects signing the meesage, the `Promise` will reject.
127
+ If the wallet is locked, or you have not connected with the wallet (or previously been whitelisted) or if the user rejects signing the meesage, the `Promise` will reject.
128
128
 
129
129
  The following exemplifies requesting a signature of a message:
130
130
 
@@ -136,6 +136,19 @@ const signature = await provider.signMessage(
136
136
  );
137
137
  ```
138
138
 
139
+ ### Add CIS-2 Tokens
140
+
141
+ It is possible to suggest CIS-2 tokens to be added to the connected account's display. sign arbitrary messages using the keys for an account stored in the wallet, by invoking the `signMessage` method. The first parameter is the account to be used for signing the message. This method returns a `Promise` resolving with a signature of the message.
142
+
143
+ If the wallet is locked, or you have not connected with the wallet (or previously been whitelisted) or if the user rejects signing the meesage, the `Promise` will reject.
144
+
145
+ The following exemplifies requesting tokens with id AA and BB from the contract on index 1399, and subindex 0 to the account `2za2yAXbFiaB151oYqTteZfqiBzibHXizwjNbpdU8hodq9SfEk`.
146
+
147
+ ```typescript
148
+ const provider = await detectConcordiumProvider();
149
+ await provider.addCIS2Tokens('2za2yAXbFiaB151oYqTteZfqiBzibHXizwjNbpdU8hodq9SfEk', ['AA', 'BB'], '1399', '0');
150
+ ```
151
+
139
152
  ## Events
140
153
 
141
154
  ### Account changed
@@ -1,4 +1,5 @@
1
- import type { AccountTransactionPayload, AccountTransactionSignature, AccountTransactionType, JsonRpcClient, SchemaVersion } from '@concordium/web-sdk';
1
+ import type { AccountTransactionPayload, AccountTransactionSignature, AccountTransactionType, InitContractPayload, JsonRpcClient, SchemaVersion, UpdateContractPayload } from '@concordium/web-sdk';
2
+ declare type SendTransactionPayload = Exclude<AccountTransactionPayload, UpdateContractPayload | InitContractPayload> | Omit<UpdateContractPayload, 'message'> | Omit<InitContractPayload, 'param'>;
2
3
  /**
3
4
  * An enumeration of the events that can be emitted by the WalletApi.
4
5
  */
@@ -21,20 +22,20 @@ interface MainWalletApi {
21
22
  * Note that if the user rejects signing the transaction, this will throw an error.
22
23
  * @param accountAddress the address of the account that should sign the transaction
23
24
  * @param type the type of transaction that is to be signed and sent.
24
- * @param payload the payload of the transaction to be signed and sent.
25
+ * @param payload the payload of the transaction to be signed and sent. Note that for smart contract transactions, the payload should not contain the params/message fields, those should instead be provided in the subsequent argument instead.
25
26
  * @param parameters parameters for the initContract and updateContract transactions in JSON-like format.
26
27
  * @param schema schema used for the initContract and updateContract transactions to serialize the parameters. Should be base64 encoded.
27
28
  * @param schemaVersion version of the schema provided. Must be supplied for schemas that use version 0 or 1, as they don't have the version embedded.
28
29
  */
29
- sendTransaction(accountAddress: string, type: AccountTransactionType.UpdateSmartContractInstance | AccountTransactionType.InitializeSmartContractInstance, payload: AccountTransactionPayload, parameters: Record<string, unknown>, schema: string, schemaVersion?: SchemaVersion): Promise<string>;
30
+ sendTransaction(accountAddress: string, type: AccountTransactionType.Update | AccountTransactionType.InitContract, payload: SendTransactionPayload, parameters: Record<string, unknown>, schema: string, schemaVersion?: SchemaVersion): Promise<string>;
30
31
  /**
31
32
  * Sends a transaction to the Concordium Wallet and awaits the users action. Note that a header is not sent, and will be constructed by the wallet itself.
32
33
  * Note that if the user rejects signing the transaction, this will throw an error.
33
34
  * @param accountAddress the address of the account that should sign the transaction
34
35
  * @param type the type of transaction that is to be signed and sent.
35
- * @param payload the payload of the transaction to be signed and sent.
36
+ * @param payload the payload of the transaction to be signed and sent. Note that for smart contract transactions, the payload should not contain the parameters, those should instead be provided in the subsequent argument instead.
36
37
  */
37
- sendTransaction(accountAddress: string, type: AccountTransactionType, payload: AccountTransactionPayload): Promise<string>;
38
+ sendTransaction(accountAddress: string, type: AccountTransactionType, payload: SendTransactionPayload): Promise<string>;
38
39
  /**
39
40
  * Sends a message to the Concordium Wallet and awaits the users action. If the user signs the message, this will resolve to the signature.
40
41
  * Note that if the user rejects signing the message, this will throw an error.
@@ -53,6 +54,12 @@ interface MainWalletApi {
53
54
  getMostRecentlySelectedAccount(): Promise<string | undefined>;
54
55
  removeAllListeners(event?: EventType | string | undefined): this;
55
56
  getJsonRpcClient(): JsonRpcClient;
57
+ /**
58
+ * Request that the user adds the specified tokens for a given contract to the wallet.
59
+ * Returns which of the given tokens the user accepted to add the tokens into the wallet.
60
+ * Note that this will throw an error if the dApp is not connected with the accountAddress.
61
+ */
62
+ addCIS2Tokens(accountAddress: string, tokenIds: string[], contractIndex: bigint, contractSubindex?: bigint): Promise<string[]>;
56
63
  }
57
64
  export declare type WalletApi = MainWalletApi & EventListeners;
58
65
  export {};
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
2
- "name": "@concordium/browser-wallet-api-helpers",
3
- "version": "0.2.0",
4
- "license": "Apache-2.0",
5
- "packageManager": "yarn@3.2.0",
6
- "main": "lib/index.js",
7
- "browser": "lib/concordiumHelpers.min.js",
8
- "types": "lib/index.d.ts",
9
- "files": [
10
- "/lib/**/*"
11
- ],
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/Concordium/concordium-browser-wallet"
15
- },
16
- "author": {
17
- "name": "Concordium Software",
18
- "email": "support@concordium.software",
19
- "url": "https://concordium.com"
20
- },
21
- "dependencies": {
22
- "@concordium/web-sdk": "^0.4.0"
23
- },
24
- "devDependencies": {
25
- "@babel/core": "^7.17.10",
26
- "@babel/plugin-transform-modules-commonjs": "^7.12.1",
27
- "@babel/plugin-transform-runtime": "^7.12.1",
28
- "@babel/preset-env": "^7.12.1",
29
- "typescript": "^4.3.5",
30
- "webpack": "^5.72.0",
31
- "webpack-cli": "^4.9.2"
32
- },
33
- "scripts": {
34
- "build": "tsc && webpack"
35
- }
36
- }
2
+ "name": "@concordium/browser-wallet-api-helpers",
3
+ "version": "2.0.0",
4
+ "license": "Apache-2.0",
5
+ "packageManager": "yarn@3.2.0",
6
+ "main": "lib/index.js",
7
+ "browser": "lib/concordiumHelpers.min.js",
8
+ "types": "lib/index.d.ts",
9
+ "files": [
10
+ "/lib/**/*"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/Concordium/concordium-browser-wallet"
15
+ },
16
+ "author": {
17
+ "name": "Concordium Software",
18
+ "email": "support@concordium.software",
19
+ "url": "https://concordium.com"
20
+ },
21
+ "dependencies": {
22
+ "@concordium/web-sdk": "^3.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@babel/core": "^7.17.10",
26
+ "@babel/plugin-transform-modules-commonjs": "^7.12.1",
27
+ "@babel/plugin-transform-runtime": "^7.12.1",
28
+ "@babel/preset-env": "^7.12.1",
29
+ "typescript": "^4.3.5",
30
+ "webpack": "^5.72.0",
31
+ "webpack-cli": "^4.9.2"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc && webpack"
35
+ }
36
+ }