@concordium/browser-wallet-api-helpers 2.2.0 → 2.4.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 CHANGED
@@ -142,7 +142,12 @@ It is possible to sign arbitrary messages using the keys for an account stored i
142
142
 
143
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
144
 
145
- The following exemplifies requesting a signature of a message:
145
+ The message should either utf8 string or an object with the following fields:
146
+
147
+ - data: A hex string representing the bytes that should be signed.
148
+ - 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.
149
+
150
+ The following exemplifies requesting a signature of a message, where the message is a utf8 string:
146
151
 
147
152
  ```typescript
148
153
  const provider = await detectConcordiumProvider();
@@ -152,6 +157,31 @@ const signature = await provider.signMessage(
152
157
  );
153
158
  ```
154
159
 
160
+ The following exemplifies requesting a signature of a message, where the message is an object:
161
+
162
+ ```typescript
163
+ const provider = await detectConcordiumProvider();
164
+ const signature = await provider.signMessage('4MyVHYbRkAU6fqQsoSDzni6mrVz1KEvhDJoMVmDmrCgPBD8b7S', {
165
+ data: '00000b0000004120676f6f64206974656d00a4fbca84010000',
166
+ schema: 'FAAEAAAADQAAAGF1Y3Rpb25fc3RhdGUVAgAAAAoAAABOb3RTb2xkWWV0AgQAAABTb2xkAQEAAAALDgAAAGhpZ2hlc3RfYmlkZGVyFQIAAAAEAAAATm9uZQIEAAAAU29tZQEBAAAACwQAAABpdGVtFgIDAAAAZW5kDQ',
167
+ });
168
+ ```
169
+
170
+ In this example the user will be shown:
171
+
172
+ ```JSON
173
+ {
174
+ "auction_state": {
175
+ "NotSoldYet": []
176
+ },
177
+ "end": "2022-12-01T00:00:00+00:00",
178
+ "highest_bidder": {
179
+ "None": []
180
+ },
181
+ "item": "A good item"
182
+ }
183
+ ```
184
+
155
185
  ### Add CIS-2 Tokens
156
186
 
157
187
  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.
@@ -165,6 +195,22 @@ const provider = await detectConcordiumProvider();
165
195
  await provider.addCIS2Tokens('2za2yAXbFiaB151oYqTteZfqiBzibHXizwjNbpdU8hodq9SfEk', ['AA', 'BB'], '1399', '0');
166
196
  ```
167
197
 
198
+ ### Prove ID statement
199
+
200
+ It is possible to request a proof for a given ID statement on a specific account. The function takes 3 arguments. The statement to be proved, a challenge to ensure that the proof was not generated for a different context, and the account that should prove that statement.
201
+ This method returns a `Promise` resolving with an object containing the proof and the credential id (field name: credential) of the credential used to prove the statement.
202
+
203
+ If the wallet is locked, or you have not connected with the wallet (or previously been whitelisted) or if the user rejects proving the statement, the `Promise` will reject.
204
+
205
+ The following exemplifies requesting a proof for a statement name myIdStatement (To see how to create a statement check out [our documentation](https://developer.concordium.software/en/mainnet/net/guides/create-proofs.html)) with a challenge of "12346789ABCD" id, for the account `2za2yAXbFiaB151oYqTteZfqiBzibHXizwjNbpdU8hodq9SfEk`.
206
+
207
+ ```typescript
208
+ const statement = myIdStatement;
209
+ const challenge = '12346789ABCD';
210
+ const provider = await detectConcordiumProvider();
211
+ await provider.requestIdProof('2za2yAXbFiaB151oYqTteZfqiBzibHXizwjNbpdU8hodq9SfEk', ['AA', 'BB'], '1399', '0');
212
+ ```
213
+
168
214
  ## Events
169
215
 
170
216
  ### Account changed
@@ -1,5 +1,14 @@
1
1
  import type { AccountTransactionPayload, AccountTransactionSignature, AccountTransactionType, InitContractPayload, JsonRpcClient, SchemaVersion, UpdateContractPayload, IdStatement, IdProofOutput } from '@concordium/web-sdk';
2
- declare type SendTransactionPayload = Exclude<AccountTransactionPayload, UpdateContractPayload | InitContractPayload> | Omit<UpdateContractPayload, 'message'> | Omit<InitContractPayload, 'param'>;
2
+ export declare type SendTransactionPayload = Exclude<AccountTransactionPayload, UpdateContractPayload | InitContractPayload> | Omit<UpdateContractPayload, 'message'> | Omit<InitContractPayload, 'param'>;
3
+ export declare type SmartContractParameters = {
4
+ [key: string]: SmartContractParameters;
5
+ } | SmartContractParameters[] | number | string | boolean;
6
+ export declare type SignMessageObject = {
7
+ /** as base64 */
8
+ schema: string;
9
+ /** as hex */
10
+ data: string;
11
+ };
3
12
  /**
4
13
  * An enumeration of the events that can be emitted by the WalletApi.
5
14
  */
@@ -35,7 +44,7 @@ interface MainWalletApi {
35
44
  * @param schema schema used for the initContract and updateContract transactions to serialize the parameters. Should be base64 encoded.
36
45
  * @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.
37
46
  */
38
- sendTransaction(accountAddress: string, type: AccountTransactionType.Update | AccountTransactionType.InitContract, payload: SendTransactionPayload, parameters: Record<string, unknown>, schema: string | SchemaWithContext, schemaVersion?: SchemaVersion): Promise<string>;
47
+ sendTransaction(accountAddress: string, type: AccountTransactionType.Update | AccountTransactionType.InitContract, payload: SendTransactionPayload, parameters: SmartContractParameters, schema: string | SchemaWithContext, schemaVersion?: SchemaVersion): Promise<string>;
39
48
  /**
40
49
  * 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.
41
50
  * Note that if the user rejects signing the transaction, this will throw an error.
@@ -48,9 +57,9 @@ interface MainWalletApi {
48
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.
49
58
  * Note that if the user rejects signing the message, this will throw an error.
50
59
  * @param accountAddress the address of the account that should sign the message
51
- * @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 }.
52
61
  */
53
- signMessage(accountAddress: string, message: string): Promise<AccountTransactionSignature>;
62
+ signMessage(accountAddress: string, message: string | SignMessageObject): Promise<AccountTransactionSignature>;
54
63
  /**
55
64
  * Requests a connection to the Concordium wallet, prompting the user to either accept or reject the request.
56
65
  * If a connection has already been accepted for the url once the returned promise will resolve without prompting the user.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@concordium/browser-wallet-api-helpers",
3
- "version": "2.2.0",
3
+ "version": "2.4.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.0"
22
+ "@concordium/web-sdk": "^3.4.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@babel/core": "^7.17.10",