@concordium/browser-wallet-api-helpers 2.3.0 → 2.5.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 +40 -1
- package/lib/wallet-api-types.d.ts +22 -3
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -74,6 +74,15 @@ if (accountAddress) {
|
|
|
74
74
|
}
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
### getSelectedChain
|
|
78
|
+
|
|
79
|
+
This can be invoked to get the genesis hash of the chain selected in the wallet. The method returns a `Promise`, resolving with the genesis hash (as a hex string) of the selected chain, or undefined if the wallet is locked or has not been set up by the user.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const provider = await detectConcordiumProvider();
|
|
83
|
+
const genesisHash = await provider.getSelectedChain();
|
|
84
|
+
```
|
|
85
|
+
|
|
77
86
|
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
87
|
|
|
79
88
|
### sendTransaction
|
|
@@ -142,7 +151,12 @@ It is possible to sign arbitrary messages using the keys for an account stored i
|
|
|
142
151
|
|
|
143
152
|
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
153
|
|
|
145
|
-
The
|
|
154
|
+
The message should be either a utf8 string or an object with the following fields:
|
|
155
|
+
|
|
156
|
+
- data: A hex string representing the bytes that should be signed.
|
|
157
|
+
- schema: A base64 string that represents a schema for the data field, and which can be used to deserialize the data into a JSON format. (For reference, the type of schema used here is the same that is used for smart contract types)
|
|
158
|
+
|
|
159
|
+
The following exemplifies requesting a signature of a message, where the message is a utf8 string:
|
|
146
160
|
|
|
147
161
|
```typescript
|
|
148
162
|
const provider = await detectConcordiumProvider();
|
|
@@ -152,6 +166,31 @@ const signature = await provider.signMessage(
|
|
|
152
166
|
);
|
|
153
167
|
```
|
|
154
168
|
|
|
169
|
+
The following exemplifies requesting a signature of a message, where the message is an object:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
const provider = await detectConcordiumProvider();
|
|
173
|
+
const signature = await provider.signMessage('4MyVHYbRkAU6fqQsoSDzni6mrVz1KEvhDJoMVmDmrCgPBD8b7S', {
|
|
174
|
+
data: '00000b0000004120676f6f64206974656d00a4fbca84010000',
|
|
175
|
+
schema: 'FAAEAAAADQAAAGF1Y3Rpb25fc3RhdGUVAgAAAAoAAABOb3RTb2xkWWV0AgQAAABTb2xkAQEAAAALDgAAAGhpZ2hlc3RfYmlkZGVyFQIAAAAEAAAATm9uZQIEAAAAU29tZQEBAAAACwQAAABpdGVtFgIDAAAAZW5kDQ',
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
In this example the user will be shown:
|
|
180
|
+
|
|
181
|
+
```JSON
|
|
182
|
+
{
|
|
183
|
+
"auction_state": {
|
|
184
|
+
"NotSoldYet": []
|
|
185
|
+
},
|
|
186
|
+
"end": "2022-12-01T00:00:00+00:00",
|
|
187
|
+
"highest_bidder": {
|
|
188
|
+
"None": []
|
|
189
|
+
},
|
|
190
|
+
"item": "A good item"
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
155
194
|
### Add CIS-2 Tokens
|
|
156
195
|
|
|
157
196
|
It is possible to suggest CIS-2 tokens to be added to an account's display. This method returns a `Promise` resolving with a list containing the ids of the tokens that were added.
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import type { AccountTransactionPayload, AccountTransactionSignature, AccountTransactionType, InitContractPayload, JsonRpcClient, SchemaVersion, UpdateContractPayload, IdStatement, IdProofOutput } from '@concordium/web-sdk';
|
|
1
|
+
import type { AccountTransactionPayload, AccountTransactionSignature, AccountTransactionType, InitContractPayload, JsonRpcClient, SchemaVersion, UpdateContractPayload, IdStatement, IdProofOutput, ConcordiumGRPCClient } from '@concordium/web-sdk';
|
|
2
2
|
export declare type SendTransactionPayload = Exclude<AccountTransactionPayload, UpdateContractPayload | InitContractPayload> | Omit<UpdateContractPayload, 'message'> | Omit<InitContractPayload, 'param'>;
|
|
3
3
|
export declare type SmartContractParameters = {
|
|
4
4
|
[key: string]: SmartContractParameters;
|
|
5
5
|
} | SmartContractParameters[] | number | string | boolean;
|
|
6
|
+
export declare type SignMessageObject = {
|
|
7
|
+
/** as base64 */
|
|
8
|
+
schema: string;
|
|
9
|
+
/** as hex */
|
|
10
|
+
data: string;
|
|
11
|
+
};
|
|
6
12
|
/**
|
|
7
13
|
* An enumeration of the events that can be emitted by the WalletApi.
|
|
8
14
|
*/
|
|
@@ -51,9 +57,9 @@ interface MainWalletApi {
|
|
|
51
57
|
* Sends a message to the Concordium Wallet and awaits the users action. If the user signs the message, this will resolve to the signature.
|
|
52
58
|
* Note that if the user rejects signing the message, this will throw an error.
|
|
53
59
|
* @param accountAddress the address of the account that should sign the message
|
|
54
|
-
* @param message message to be signed. Note that the wallet will prepend some bytes to ensure the message cannot be a transaction
|
|
60
|
+
* @param message message to be signed. Note that the wallet will prepend some bytes to ensure the message cannot be a transaction. The message should either be a utf8 string or { @link SignMessageObject }.
|
|
55
61
|
*/
|
|
56
|
-
signMessage(accountAddress: string, message: string): Promise<AccountTransactionSignature>;
|
|
62
|
+
signMessage(accountAddress: string, message: string | SignMessageObject): Promise<AccountTransactionSignature>;
|
|
57
63
|
/**
|
|
58
64
|
* Requests a connection to the Concordium wallet, prompting the user to either accept or reject the request.
|
|
59
65
|
* If a connection has already been accepted for the url once the returned promise will resolve without prompting the user.
|
|
@@ -64,7 +70,20 @@ interface MainWalletApi {
|
|
|
64
70
|
*/
|
|
65
71
|
getMostRecentlySelectedAccount(): Promise<string | undefined>;
|
|
66
72
|
removeAllListeners(event?: EventType | string | undefined): this;
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated use { @link getGrpcClient} instead
|
|
75
|
+
*/
|
|
67
76
|
getJsonRpcClient(): JsonRpcClient;
|
|
77
|
+
/**
|
|
78
|
+
* Returns a gRPC client that is connected to the node that the wallet is.
|
|
79
|
+
* Note that any calls will throw an error, if the site is not connected with the wallet.
|
|
80
|
+
*/
|
|
81
|
+
getGrpcClient(): ConcordiumGRPCClient;
|
|
82
|
+
/**
|
|
83
|
+
* Returns the genesis hash of the currently selected chain in the wallet.
|
|
84
|
+
* Returns undefined if the wallet is either locked or not set up by the user.
|
|
85
|
+
*/
|
|
86
|
+
getSelectedChain(): Promise<string | undefined>;
|
|
68
87
|
/**
|
|
69
88
|
* Request that the user adds the specified tokens for a given contract to the wallet.
|
|
70
89
|
* Returns which of the given tokens the user accepted to add the tokens into the wallet.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@concordium/browser-wallet-api-helpers",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.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": "^3.2
|
|
22
|
+
"@concordium/web-sdk": "^3.4.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/core": "^7.17.10",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"webpack-cli": "^4.9.2"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
|
-
"build": "tsc && webpack"
|
|
34
|
+
"build": "tsc && webpack",
|
|
35
|
+
"build:api-helpers": "yarn build"
|
|
35
36
|
}
|
|
36
37
|
}
|