@concordium/browser-wallet-api-helpers 0.2.0 → 1.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/README.md +7 -7
- package/lib/wallet-api-types.d.ts +6 -5
- package/package.json +2 -2
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](
|
|
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
|
|
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
|
|
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
|
|
|
@@ -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, 'parameter'> | Omit<InitContractPayload, 'parameter'>;
|
|
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 parameters, 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:
|
|
30
|
+
sendTransaction(accountAddress: string, type: AccountTransactionType.UpdateSmartContractInstance | AccountTransactionType.InitializeSmartContractInstance, 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:
|
|
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@concordium/browser-wallet-api-helpers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"packageManager": "yarn@3.2.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"url": "https://concordium.com"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@concordium/web-sdk": "^0.
|
|
22
|
+
"@concordium/web-sdk": "^2.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/core": "^7.17.10",
|