@concordium/browser-wallet-api-helpers 2.0.0 → 2.2.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 +18 -2
- package/lib/concordiumHelpers.min.js +1 -1
- package/lib/concordiumHelpers.min.js.map +1 -1
- package/lib/wallet-api-types.d.ts +23 -2
- package/lib/wallet-api-types.js +5 -0
- package/package.json +35 -35
- package/CHANGELOG.md +0 -39
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.
|
|
@@ -138,7 +154,7 @@ const signature = await provider.signMessage(
|
|
|
138
154
|
|
|
139
155
|
### Add CIS-2 Tokens
|
|
140
156
|
|
|
141
|
-
It is possible to suggest CIS-2 tokens to be added to
|
|
157
|
+
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.
|
|
142
158
|
|
|
143
159
|
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
160
|
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import type { AccountTransactionPayload, AccountTransactionSignature, AccountTransactionType, InitContractPayload, JsonRpcClient, SchemaVersion, UpdateContractPayload } from '@concordium/web-sdk';
|
|
1
|
+
import type { AccountTransactionPayload, AccountTransactionSignature, AccountTransactionType, InitContractPayload, JsonRpcClient, SchemaVersion, UpdateContractPayload, IdStatement, IdProofOutput } from '@concordium/web-sdk';
|
|
2
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.
|
|
@@ -8,6 +8,14 @@ export declare enum EventType {
|
|
|
8
8
|
AccountDisconnected = "accountDisconnected",
|
|
9
9
|
ChainChanged = "chainChanged"
|
|
10
10
|
}
|
|
11
|
+
export declare enum SchemaType {
|
|
12
|
+
Module = "module",
|
|
13
|
+
Parameter = "parameter"
|
|
14
|
+
}
|
|
15
|
+
export declare type SchemaWithContext = {
|
|
16
|
+
type: SchemaType;
|
|
17
|
+
value: string;
|
|
18
|
+
};
|
|
11
19
|
declare type EventListener<Args extends any[]> = (...args: Args) => void;
|
|
12
20
|
interface Listeners<T extends EventType, Args extends any[]> {
|
|
13
21
|
on(eventName: T | `${T}`, listener: EventListener<Args>): this;
|
|
@@ -27,7 +35,7 @@ interface MainWalletApi {
|
|
|
27
35
|
* @param schema schema used for the initContract and updateContract transactions to serialize the parameters. Should be base64 encoded.
|
|
28
36
|
* @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
37
|
*/
|
|
30
|
-
sendTransaction(accountAddress: string, type: AccountTransactionType.Update | AccountTransactionType.InitContract, payload: SendTransactionPayload, parameters: Record<string, unknown>, schema: string, schemaVersion?: SchemaVersion): Promise<string>;
|
|
38
|
+
sendTransaction(accountAddress: string, type: AccountTransactionType.Update | AccountTransactionType.InitContract, payload: SendTransactionPayload, parameters: Record<string, unknown>, schema: string | SchemaWithContext, schemaVersion?: SchemaVersion): Promise<string>;
|
|
31
39
|
/**
|
|
32
40
|
* 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
41
|
* Note that if the user rejects signing the transaction, this will throw an error.
|
|
@@ -58,8 +66,21 @@ interface MainWalletApi {
|
|
|
58
66
|
* Request that the user adds the specified tokens for a given contract to the wallet.
|
|
59
67
|
* Returns which of the given tokens the user accepted to add the tokens into the wallet.
|
|
60
68
|
* Note that this will throw an error if the dApp is not connected with the accountAddress.
|
|
69
|
+
* @param accountAddress the address of the account whose display the tokens should be added to.
|
|
70
|
+
* @param tokenIds the list of ids, for the tokens that should be added.
|
|
71
|
+
* @param contractIndex the index of the CIS-2 contract which the tokens are in.
|
|
72
|
+
* @param contractSubindex the subindex of the CIS-2 contract which the tokens are in.
|
|
73
|
+
* @returns a list containing the ids of the tokens that was added to the wallet.
|
|
61
74
|
*/
|
|
62
75
|
addCIS2Tokens(accountAddress: string, tokenIds: string[], contractIndex: bigint, contractSubindex?: bigint): Promise<string[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Request that the user provides a proof for the given statement.
|
|
78
|
+
* @param accountAddress the address of the account that should prove the statement.
|
|
79
|
+
* @param statement the id statement that should be proven.
|
|
80
|
+
* @param challenge bytes chosen by the verifier. Should be HEX encoded.
|
|
81
|
+
* @returns The id proof and the id of the credential used to prove it.
|
|
82
|
+
*/
|
|
83
|
+
requestIdProof(accountAddress: string, statement: IdStatement, challenge: string): Promise<IdProofOutput>;
|
|
63
84
|
}
|
|
64
85
|
export declare type WalletApi = MainWalletApi & EventListeners;
|
|
65
86
|
export {};
|
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,36 +1,36 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
2
|
+
"name": "@concordium/browser-wallet-api-helpers",
|
|
3
|
+
"version": "2.2.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.2.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
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
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.
|