@concordium/browser-wallet-api-helpers 1.0.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
@@ -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,5 +1,5 @@
1
1
  import type { AccountTransactionPayload, AccountTransactionSignature, AccountTransactionType, InitContractPayload, JsonRpcClient, SchemaVersion, UpdateContractPayload } from '@concordium/web-sdk';
2
- declare type SendTransactionPayload = Exclude<AccountTransactionPayload, UpdateContractPayload | InitContractPayload> | Omit<UpdateContractPayload, 'parameter'> | Omit<InitContractPayload, 'parameter'>;
2
+ declare type SendTransactionPayload = Exclude<AccountTransactionPayload, UpdateContractPayload | InitContractPayload> | Omit<UpdateContractPayload, 'message'> | Omit<InitContractPayload, 'param'>;
3
3
  /**
4
4
  * An enumeration of the events that can be emitted by the WalletApi.
5
5
  */
@@ -22,12 +22,12 @@ interface MainWalletApi {
22
22
  * Note that if the user rejects signing the transaction, this will throw an error.
23
23
  * @param accountAddress the address of the account that should sign the transaction
24
24
  * @param type the type of transaction that is 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 parameters, those should instead be provided in the subsequent argument instead.
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.
26
26
  * @param parameters parameters for the initContract and updateContract transactions in JSON-like format.
27
27
  * @param schema schema used for the initContract and updateContract transactions to serialize the parameters. Should be base64 encoded.
28
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.
29
29
  */
30
- sendTransaction(accountAddress: string, type: AccountTransactionType.UpdateSmartContractInstance | AccountTransactionType.InitializeSmartContractInstance, payload: SendTransactionPayload, 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>;
31
31
  /**
32
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.
33
33
  * Note that if the user rejects signing the transaction, this will throw an error.
@@ -54,6 +54,12 @@ interface MainWalletApi {
54
54
  getMostRecentlySelectedAccount(): Promise<string | undefined>;
55
55
  removeAllListeners(event?: EventType | string | undefined): this;
56
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[]>;
57
63
  }
58
64
  export declare type WalletApi = MainWalletApi & EventListeners;
59
65
  export {};
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
2
- "name": "@concordium/browser-wallet-api-helpers",
3
- "version": "1.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": "^2.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
- }
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
+ }