@concordium/browser-wallet-api-helpers 2.1.0 → 2.3.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
|
@@ -115,11 +115,27 @@ const txHash = await provider.sendTransaction(
|
|
|
115
115
|
{
|
|
116
116
|
RequestTransfer: ['1000', '1', '3Y1RLgi5pW3x96xZ7CiDiKsTL9huU92qn6mfxpebwmtkeku8ry'],
|
|
117
117
|
},
|
|
118
|
-
|
|
118
|
+
{
|
|
119
|
+
type: SchemaType.Module,
|
|
120
|
+
value: 'AQAAABEAAAB0d28tc3RlcC10cmFuc2ZlcgEUAAIAAAALAAAAaW5pdF9wYXJhbXMUAAMAAAAPAAAAYWNjb3VudF9ob2xkZXJzEQALHAAAAHRyYW5zZmVyX2FncmVlbWVudF90aHJlc2hvbGQCFAAAAHRyYW5zZmVyX3JlcXVlc3RfdHRsDggAAAByZXF1ZXN0cxIBBRQABAAAAA8AAAB0cmFuc2Zlcl9hbW91bnQKDgAAAHRhcmdldF9hY2NvdW50CwwAAAB0aW1lc19vdXRfYXQNCgAAAHN1cHBvcnRlcnMRAgsBFAADAAAADwAAAGFjY291bnRfaG9sZGVycxEACxwAAAB0cmFuc2Zlcl9hZ3JlZW1lbnRfdGhyZXNob2xkAhQAAAB0cmFuc2Zlcl9yZXF1ZXN0X3R0bA4BAAAABwAAAHJlY2VpdmUVAgAAAA8AAABSZXF1ZXN0VHJhbnNmZXIBAwAAAAUKCw8AAABTdXBwb3J0VHJhbnNmZXIBAwAAAAUKCw==',
|
|
121
|
+
},
|
|
119
122
|
0
|
|
120
123
|
);
|
|
121
124
|
```
|
|
122
125
|
|
|
126
|
+
Note that the schema should specify whether it is for the parameter's specific type or for the entire module. To specify the different schema type:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
const moduleSchema = {
|
|
130
|
+
type: SchemaType.Module,
|
|
131
|
+
value: ... // base64 string
|
|
132
|
+
}
|
|
133
|
+
const parameterSchema = {
|
|
134
|
+
type SchemaType.Parameter,
|
|
135
|
+
value: ... // base64 string
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
123
139
|
### signMessage
|
|
124
140
|
|
|
125
141
|
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.
|
|
@@ -149,6 +165,22 @@ const provider = await detectConcordiumProvider();
|
|
|
149
165
|
await provider.addCIS2Tokens('2za2yAXbFiaB151oYqTteZfqiBzibHXizwjNbpdU8hodq9SfEk', ['AA', 'BB'], '1399', '0');
|
|
150
166
|
```
|
|
151
167
|
|
|
168
|
+
### Prove ID statement
|
|
169
|
+
|
|
170
|
+
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.
|
|
171
|
+
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.
|
|
172
|
+
|
|
173
|
+
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.
|
|
174
|
+
|
|
175
|
+
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`.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
const statement = myIdStatement;
|
|
179
|
+
const challenge = '12346789ABCD';
|
|
180
|
+
const provider = await detectConcordiumProvider();
|
|
181
|
+
await provider.requestIdProof('2za2yAXbFiaB151oYqTteZfqiBzibHXizwjNbpdU8hodq9SfEk', ['AA', 'BB'], '1399', '0');
|
|
182
|
+
```
|
|
183
|
+
|
|
152
184
|
## Events
|
|
153
185
|
|
|
154
186
|
### Account changed
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.concordiumHelpers=o():e.concordiumHelpers=o()}(self,(()=>(()=>{"use strict";var e={611:(e,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.detectConcordiumProvider=async function(e=5e3){return new Promise(((o,n)=>{if(window.concordium)o(window.concordium);else{const t=setTimeout((()=>{window.concordium?o(window.concordium):n()}),e);window.addEventListener("concordium#initialized",(()=>{window.concordium&&(clearTimeout(t),o(window.concordium))}),{once:!0})}}))}},685:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0});var t={detectConcordiumProvider:!0};Object.defineProperty(o,"detectConcordiumProvider",{enumerable:!0,get:function(){return c.detectConcordiumProvider}});var r=n(740);Object.keys(r).forEach((function(e){"default"!==e&&"__esModule"!==e&&(Object.prototype.hasOwnProperty.call(t,e)||e in o&&o[e]===r[e]||Object.defineProperty(o,e,{enumerable:!0,get:function(){return r[e]}}))}));var c=n(611)},740:(e,o)=>{var n;Object.defineProperty(o,"__esModule",{value:!0}),o.EventType=void 0,o.EventType=n,function(e){e.AccountChanged="accountChanged",e.AccountDisconnected="accountDisconnected",e.ChainChanged="chainChanged"}(n||(o.EventType=n={}))}},o={};return function n(t){var r=o[t];if(void 0!==r)return r.exports;var c=o[t]={exports:{}};return e[t](c,c.exports,n),c.exports}(685)})()));
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.concordiumHelpers=o():e.concordiumHelpers=o()}(self,(()=>(()=>{"use strict";var e={611:(e,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.detectConcordiumProvider=async function(e=5e3){return new Promise(((o,n)=>{if(window.concordium)o(window.concordium);else{const t=setTimeout((()=>{window.concordium?o(window.concordium):n()}),e);window.addEventListener("concordium#initialized",(()=>{window.concordium&&(clearTimeout(t),o(window.concordium))}),{once:!0})}}))}},685:(e,o,n)=>{Object.defineProperty(o,"__esModule",{value:!0});var t={detectConcordiumProvider:!0};Object.defineProperty(o,"detectConcordiumProvider",{enumerable:!0,get:function(){return c.detectConcordiumProvider}});var r=n(740);Object.keys(r).forEach((function(e){"default"!==e&&"__esModule"!==e&&(Object.prototype.hasOwnProperty.call(t,e)||e in o&&o[e]===r[e]||Object.defineProperty(o,e,{enumerable:!0,get:function(){return r[e]}}))}));var c=n(611)},740:(e,o)=>{var n,t;Object.defineProperty(o,"__esModule",{value:!0}),o.SchemaType=o.EventType=void 0,o.EventType=n,function(e){e.AccountChanged="accountChanged",e.AccountDisconnected="accountDisconnected",e.ChainChanged="chainChanged"}(n||(o.EventType=n={})),o.SchemaType=t,function(e){e.Module="module",e.Parameter="parameter"}(t||(o.SchemaType=t={}))}},o={};return function n(t){var r=o[t];if(void 0!==r)return r.exports;var c=o[t]={exports:{}};return e[t](c,c.exports,n),c.exports}(685)})()));
|
|
2
2
|
//# sourceMappingURL=concordiumHelpers.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concordiumHelpers.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAA2B,kBAAID,IAE/BD,EAAwB,kBAAIC,IAR9B,CASGK,MAAM,I,kHCHFC,eAAwCC,EAAU,KACrD,OAAO,IAAIC,SAAQ,CAACC,EAASC,KACzB,GAAIC,OAAOC,WACPH,EAAQE,OAAOC,gBAEd,CACD,MAAMC,EAAIC,YAAW,KACbH,OAAOC,WACPH,EAAQE,OAAOC,YAGfF,MAELH,GACHI,OAAOI,iBAAiB,0BAA0B,KAC1CJ,OAAOC,aACPI,aAAaH,GACbJ,EAAQE,OAAOC,eAEpB,CAAEK,MAAM,U,yNCzBvB,8NACA,c,YCEO,IAAIC,E,
|
|
1
|
+
{"version":3,"file":"concordiumHelpers.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAA2B,kBAAID,IAE/BD,EAAwB,kBAAIC,IAR9B,CASGK,MAAM,I,kHCHFC,eAAwCC,EAAU,KACrD,OAAO,IAAIC,SAAQ,CAACC,EAASC,KACzB,GAAIC,OAAOC,WACPH,EAAQE,OAAOC,gBAEd,CACD,MAAMC,EAAIC,YAAW,KACbH,OAAOC,WACPH,EAAQE,OAAOC,YAGfF,MAELH,GACHI,OAAOI,iBAAiB,0BAA0B,KAC1CJ,OAAOC,aACPI,aAAaH,GACbJ,EAAQE,OAAOC,eAEpB,CAAEK,MAAM,U,yNCzBvB,8NACA,c,YCEO,IAAIC,EAMAC,E,+FALX,SAAWD,GACPA,EAAS,eAAqB,iBAC9BA,EAAS,oBAA0B,sBACnCA,EAAS,aAAmB,eAHhC,CAIGA,IAAc,EAAAA,UAAAA,EAAY,K,eAE7B,SAAWC,GACPA,EAAU,OAAa,SACvBA,EAAU,UAAgB,YAF9B,CAGGA,IAAe,EAAAA,WAAAA,EAAa,OCZ3BC,EAA2B,G,OAG/B,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAatB,QAGrB,IAAIC,EAASkB,EAAyBE,GAAY,CAGjDrB,QAAS,IAOV,OAHAwB,EAAoBH,GAAUpB,EAAQA,EAAOD,QAASoB,GAG/CnB,EAAOD,QClBWoB,CAAoB,M","sources":["webpack:///webpack/universalModuleDefinition","webpack:///./lib/detector.js","webpack:///./lib/index.js","webpack:///./lib/wallet-api-types.js","webpack:///webpack/bootstrap","webpack:///webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"concordiumHelpers\"] = factory();\n\telse\n\t\troot[\"concordiumHelpers\"] = factory();\n})(self, () => {\nreturn ","/**\n * Detect the Concordium browser wallet API by waiting for it to have been successfully injected\n * into the window so that it is ready for use.\n * @param timeout determines how long to wait before rejecting if the Concordium provider is not available, in milliseconds.\n * @returns a promise containing the Concordium Wallet provider API.\n */\nexport async function detectConcordiumProvider(timeout = 5000) {\n return new Promise((resolve, reject) => {\n if (window.concordium) {\n resolve(window.concordium);\n }\n else {\n const t = setTimeout(() => {\n if (window.concordium) {\n resolve(window.concordium);\n }\n else {\n reject();\n }\n }, timeout);\n window.addEventListener('concordium#initialized', () => {\n if (window.concordium) {\n clearTimeout(t);\n resolve(window.concordium);\n }\n }, { once: true });\n }\n });\n}\n","export * from './wallet-api-types';\nexport { detectConcordiumProvider } from './detector';\n","/**\n * An enumeration of the events that can be emitted by the WalletApi.\n */\nexport var EventType;\n(function (EventType) {\n EventType[\"AccountChanged\"] = \"accountChanged\";\n EventType[\"AccountDisconnected\"] = \"accountDisconnected\";\n EventType[\"ChainChanged\"] = \"chainChanged\";\n})(EventType || (EventType = {}));\nexport var SchemaType;\n(function (SchemaType) {\n SchemaType[\"Module\"] = \"module\";\n SchemaType[\"Parameter\"] = \"parameter\";\n})(SchemaType || (SchemaType = {}));\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(685);\n"],"names":["root","factory","exports","module","define","amd","self","async","timeout","Promise","resolve","reject","window","concordium","t","setTimeout","addEventListener","clearTimeout","once","EventType","SchemaType","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__"],"sourceRoot":""}
|
|
@@ -1,5 +1,8 @@
|
|
|
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;
|
|
3
6
|
/**
|
|
4
7
|
* An enumeration of the events that can be emitted by the WalletApi.
|
|
5
8
|
*/
|
|
@@ -8,6 +11,14 @@ export declare enum EventType {
|
|
|
8
11
|
AccountDisconnected = "accountDisconnected",
|
|
9
12
|
ChainChanged = "chainChanged"
|
|
10
13
|
}
|
|
14
|
+
export declare enum SchemaType {
|
|
15
|
+
Module = "module",
|
|
16
|
+
Parameter = "parameter"
|
|
17
|
+
}
|
|
18
|
+
export declare type SchemaWithContext = {
|
|
19
|
+
type: SchemaType;
|
|
20
|
+
value: string;
|
|
21
|
+
};
|
|
11
22
|
declare type EventListener<Args extends any[]> = (...args: Args) => void;
|
|
12
23
|
interface Listeners<T extends EventType, Args extends any[]> {
|
|
13
24
|
on(eventName: T | `${T}`, listener: EventListener<Args>): this;
|
|
@@ -27,7 +38,7 @@ interface MainWalletApi {
|
|
|
27
38
|
* @param schema schema used for the initContract and updateContract transactions to serialize the parameters. Should be base64 encoded.
|
|
28
39
|
* @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
40
|
*/
|
|
30
|
-
sendTransaction(accountAddress: string, type: AccountTransactionType.Update | AccountTransactionType.InitContract, payload: SendTransactionPayload, parameters:
|
|
41
|
+
sendTransaction(accountAddress: string, type: AccountTransactionType.Update | AccountTransactionType.InitContract, payload: SendTransactionPayload, parameters: SmartContractParameters, schema: string | SchemaWithContext, schemaVersion?: SchemaVersion): Promise<string>;
|
|
31
42
|
/**
|
|
32
43
|
* 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
44
|
* Note that if the user rejects signing the transaction, this will throw an error.
|
package/lib/wallet-api-types.js
CHANGED
|
@@ -7,3 +7,8 @@ export var EventType;
|
|
|
7
7
|
EventType["AccountDisconnected"] = "accountDisconnected";
|
|
8
8
|
EventType["ChainChanged"] = "chainChanged";
|
|
9
9
|
})(EventType || (EventType = {}));
|
|
10
|
+
export var SchemaType;
|
|
11
|
+
(function (SchemaType) {
|
|
12
|
+
SchemaType["Module"] = "module";
|
|
13
|
+
SchemaType["Parameter"] = "parameter";
|
|
14
|
+
})(SchemaType || (SchemaType = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@concordium/browser-wallet-api-helpers",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.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.
|
|
22
|
+
"@concordium/web-sdk": "^3.2.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/core": "^7.17.10",
|