UNPKG

@simbachain/libsimba-js

Version:

libsimba-js is a library simplifying the use of SIMBAChain APIs. We aim to abstract away the various blockchain concepts, reducing the necessary time needed to get to working code.

1,431 lines (1,430 loc) 866 kB
{ "type": "File", "start": 0, "end": 7835, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 207, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 7835, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 207, "column": 0 } }, "sourceType": "module", "body": [ { "type": "ImportDeclaration", "start": 0, "end": 30, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", "start": 7, "end": 13, "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 13 } }, "local": { "type": "Identifier", "start": 7, "end": 13, "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 13 }, "identifierName": "Wallet" }, "name": "Wallet" } } ], "source": { "type": "StringLiteral", "start": 19, "end": 29, "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 29 } }, "extra": { "rawValue": "./wallet", "raw": "'./wallet'" }, "value": "./wallet" } }, { "type": "ImportDeclaration", "start": 31, "end": 94, "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 63 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 40, "end": 62, "loc": { "start": { "line": 2, "column": 9 }, "end": { "line": 2, "column": 31 } }, "imported": { "type": "Identifier", "start": 40, "end": 46, "loc": { "start": { "line": 2, "column": 9 }, "end": { "line": 2, "column": 15 }, "identifierName": "Wallet" }, "name": "Wallet" }, "local": { "type": "Identifier", "start": 50, "end": 62, "loc": { "start": { "line": 2, "column": 19 }, "end": { "line": 2, "column": 31 }, "identifierName": "EthersWallet" }, "name": "EthersWallet" } } ], "source": { "type": "StringLiteral", "start": 70, "end": 93, "loc": { "start": { "line": 2, "column": 39 }, "end": { "line": 2, "column": 62 } }, "extra": { "rawValue": "@ethersproject/wallet", "raw": "'@ethersproject/wallet'" }, "value": "@ethersproject/wallet" } }, { "type": "ImportDeclaration", "start": 95, "end": 244, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 149 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 104, "end": 120, "loc": { "start": { "line": 3, "column": 9 }, "end": { "line": 3, "column": 25 } }, "imported": { "type": "Identifier", "start": 104, "end": 120, "loc": { "start": { "line": 3, "column": 9 }, "end": { "line": 3, "column": 25 }, "identifierName": "SigningException" }, "name": "SigningException" }, "local": { "type": "Identifier", "start": 104, "end": 120, "loc": { "start": { "line": 3, "column": 9 }, "end": { "line": 3, "column": 25 }, "identifierName": "SigningException" }, "name": "SigningException" } }, { "type": "ImportSpecifier", "start": 122, "end": 150, "loc": { "start": { "line": 3, "column": 27 }, "end": { "line": 3, "column": 55 } }, "imported": { "type": "Identifier", "start": 122, "end": 150, "loc": { "start": { "line": 3, "column": 27 }, "end": { "line": 3, "column": 55 }, "identifierName": "UserRejectedSigningException" }, "name": "UserRejectedSigningException" }, "local": { "type": "Identifier", "start": 122, "end": 150, "loc": { "start": { "line": 3, "column": 27 }, "end": { "line": 3, "column": 55 }, "identifierName": "UserRejectedSigningException" }, "name": "UserRejectedSigningException" } }, { "type": "ImportSpecifier", "start": 152, "end": 175, "loc": { "start": { "line": 3, "column": 57 }, "end": { "line": 3, "column": 80 } }, "imported": { "type": "Identifier", "start": 152, "end": 175, "loc": { "start": { "line": 3, "column": 57 }, "end": { "line": 3, "column": 80 }, "identifierName": "WalletNotFoundException" }, "name": "WalletNotFoundException" }, "local": { "type": "Identifier", "start": 152, "end": 175, "loc": { "start": { "line": 3, "column": 57 }, "end": { "line": 3, "column": 80 }, "identifierName": "WalletNotFoundException" }, "name": "WalletNotFoundException" } }, { "type": "ImportSpecifier", "start": 177, "end": 198, "loc": { "start": { "line": 3, "column": 82 }, "end": { "line": 3, "column": 103 } }, "imported": { "type": "Identifier", "start": 177, "end": 198, "loc": { "start": { "line": 3, "column": 82 }, "end": { "line": 3, "column": 103 }, "identifierName": "WalletLockedException" }, "name": "WalletLockedException" }, "local": { "type": "Identifier", "start": 177, "end": 198, "loc": { "start": { "line": 3, "column": 82 }, "end": { "line": 3, "column": 103 }, "identifierName": "WalletLockedException" }, "name": "WalletLockedException" } }, { "type": "ImportSpecifier", "start": 200, "end": 221, "loc": { "start": { "line": 3, "column": 105 }, "end": { "line": 3, "column": 126 } }, "imported": { "type": "Identifier", "start": 200, "end": 221, "loc": { "start": { "line": 3, "column": 105 }, "end": { "line": 3, "column": 126 }, "identifierName": "NotInBrowserException" }, "name": "NotInBrowserException" }, "local": { "type": "Identifier", "start": 200, "end": 221, "loc": { "start": { "line": 3, "column": 105 }, "end": { "line": 3, "column": 126 }, "identifierName": "NotInBrowserException" }, "name": "NotInBrowserException" } } ], "source": { "type": "StringLiteral", "start": 228, "end": 243, "loc": { "start": { "line": 3, "column": 133 }, "end": { "line": 3, "column": 148 } }, "extra": { "rawValue": "../exceptions", "raw": "\"../exceptions\"" }, "value": "../exceptions" }, "trailingComments": [ { "type": "CommentBlock", "value": "*\n * libsimba-js Local Wallet implementation\n * Stores the wallet as encrypted json within the browsers localstorage\n * Wraps the [ethersjs]{@link https://docs.ethers.io/ethers.js/html/} library.\n ", "start": 246, "end": 447, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 9, "column": 3 } } } ] }, { "type": "ExportDefaultDeclaration", "start": 448, "end": 7834, "loc": { "start": { "line": 10, "column": 0 }, "end": { "line": 206, "column": 1 } }, "declaration": { "type": "ClassDeclaration", "start": 463, "end": 7834, "loc": { "start": { "line": 10, "column": 15 }, "end": { "line": 206, "column": 1 } }, "id": { "type": "Identifier", "start": 469, "end": 480, "loc": { "start": { "line": 10, "column": 21 }, "end": { "line": 10, "column": 32 }, "identifierName": "LocalWallet" }, "name": "LocalWallet", "leadingComments": null }, "superClass": { "type": "Identifier", "start": 489, "end": 495, "loc": { "start": { "line": 10, "column": 41 }, "end": { "line": 10, "column": 47 }, "identifierName": "Wallet" }, "name": "Wallet" }, "body": { "type": "ClassBody", "start": 496, "end": 7834, "loc": { "start": { "line": 10, "column": 48 }, "end": { "line": 206, "column": 1 } }, "body": [ { "type": "ClassMethod", "start": 790, "end": 1042, "loc": { "start": { "line": 16, "column": 4 }, "end": { "line": 23, "column": 5 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 790, "end": 801, "loc": { "start": { "line": 16, "column": 4 }, "end": { "line": 16, "column": 15 }, "identifierName": "constructor" }, "name": "constructor", "leadingComments": null }, "kind": "constructor", "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 802, "end": 821, "loc": { "start": { "line": 16, "column": 16 }, "end": { "line": 16, "column": 35 }, "identifierName": "signingConfirmation" }, "name": "signingConfirmation" } ], "body": { "type": "BlockStatement", "start": 823, "end": 1042, "loc": { "start": { "line": 16, "column": 37 }, "end": { "line": 23, "column": 5 } }, "body": [ { "type": "ExpressionStatement", "start": 833, "end": 860, "loc": { "start": { "line": 17, "column": 8 }, "end": { "line": 17, "column": 35 } }, "expression": { "type": "CallExpression", "start": 833, "end": 859, "loc": { "start": { "line": 17, "column": 8 }, "end": { "line": 17, "column": 34 } }, "callee": { "type": "Super", "start": 833, "end": 838, "loc": { "start": { "line": 17, "column": 8 }, "end": { "line": 17, "column": 13 } } }, "arguments": [ { "type": "Identifier", "start": 839, "end": 858, "loc": { "start": { "line": 17, "column": 14 }, "end": { "line": 17, "column": 33 }, "identifierName": "signingConfirmation" }, "name": "signingConfirmation" } ] } }, { "type": "IfStatement", "start": 869, "end": 1005, "loc": { "start": { "line": 18, "column": 8 }, "end": { "line": 20, "column": 9 } }, "test": { "type": "BinaryExpression", "start": 872, "end": 901, "loc": { "start": { "line": 18, "column": 11 }, "end": { "line": 18, "column": 40 } }, "left": { "type": "UnaryExpression", "start": 872, "end": 885, "loc": { "start": { "line": 18, "column": 11 }, "end": { "line": 18, "column": 24 } }, "operator": "typeof", "prefix": true, "argument": { "type": "Identifier", "start": 879, "end": 885, "loc": { "start": { "line": 18, "column": 18 }, "end": { "line": 18, "column": 24 }, "identifierName": "window" }, "name": "window" }, "extra": { "parenthesizedArgument": false } }, "operator": "===", "right": { "type": "StringLiteral", "start": 890, "end": 901, "loc": { "start": { "line": 18, "column": 29 }, "end": { "line": 18, "column": 40 } }, "extra": { "rawValue": "undefined", "raw": "'undefined'" }, "value": "undefined" } }, "consequent": { "type": "BlockStatement", "start": 903, "end": 1005, "loc": { "start": { "line": 18, "column": 42 }, "end": { "line": 20, "column": 9 } }, "body": [ { "type": "ThrowStatement", "start": 917, "end": 995, "loc": { "start": { "line": 19, "column": 12 }, "end": { "line": 19, "column": 90 } }, "argument": { "type": "NewExpression", "start": 923, "end": 994, "loc": { "start": { "line": 19, "column": 18 }, "end": { "line": 19, "column": 89 } }, "callee": { "type": "Identifier", "start": 927, "end": 948, "loc": { "start": { "line": 19, "column": 22 }, "end": { "line": 19, "column": 43 }, "identifierName": "NotInBrowserException" }, "name": "NotInBrowserException" }, "arguments": [ { "type": "StringLiteral", "start": 949, "end": 993, "loc": { "start": { "line": 19, "column": 44 }, "end": { "line": 19, "column": 88 } }, "extra": { "rawValue": "LocalWallet can only be used in a browser!", "raw": "\"LocalWallet can only be used in a browser!\"" }, "value": "LocalWallet can only be used in a browser!" } ] } } ], "directives": [] }, "alternate": null }, { "type": "ExpressionStatement", "start": 1015, "end": 1036, "loc": { "start": { "line": 22, "column": 8 }, "end": { "line": 22, "column": 29 } }, "expression": { "type": "AssignmentExpression", "start": 1015, "end": 1035, "loc": { "start": { "line": 22, "column": 8 }, "end": { "line": 22, "column": 28 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 1015, "end": 1026, "loc": { "start": { "line": 22, "column": 8 }, "end": { "line": 22, "column": 19 } }, "object": { "type": "ThisExpression", "start": 1015, "end": 1019, "loc": { "start": { "line": 22, "column": 8 }, "end": { "line": 22, "column": 12 } } }, "property": { "type": "Identifier", "start": 1020, "end": 1026, "loc": { "start": { "line": 22, "column": 13 }, "end": { "line": 22, "column": 19 }, "identifierName": "window" }, "name": "window" }, "computed": false }, "right": { "type": "Identifier", "start": 1029, "end": 1035, "loc": { "start": { "line": 22, "column": 22 }, "end": { "line": 22, "column": 28 }, "identifierName": "window" }, "name": "window" } } } ], "directives": [], "trailingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\n * Use a wallet stored in the browsers local storage\n * @param {function} [signingConfirmation] - - an optional callback for requesting user permission to sign a\n * transaction. Should resolve a promise with true for accept, and false (or reject) for reject.\n ", "start": 502, "end": 785, "loc": { "start": { "line": 11, "column": 4 }, "end": { "line": 15, "column": 7 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\n * @override\n * Unlock the wallet\n * @param {string} passkey - The pass key to unlock the wallet\n * @param {function} [progressCB] - A callback, accepting a number between 0-1, indicating decryption progress\n * @returns {Promise} - Returns a promise resolving when the wallet is unlocked\n ", "start": 1048, "end": 1367, "loc": { "start": { "line": 25, "column": 4 }, "end": { "line": 31, "column": 7 } } } ] }, { "type": "ClassMethod", "start": 1372, "end": 1577, "loc": { "start": { "line": 32, "column": 4 }, "end": { "line": 35, "column": 5 } }, "static": false, "computed": false, "key": { "type": "Identifier", "start": 1372, "end": 1384, "loc": { "start": { "line": 32, "column": 4 }, "end": { "line": 32, "column": 16 }, "identifierName": "unlockWallet" }, "name": "unlockWallet", "leadingComments": null }, "kind": "method", "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 1385, "end": 1392, "loc": { "start": { "line": 32, "column": 17 }, "end": { "line": 32, "column": 24 }, "identifierName": "passkey" }, "name": "passkey" }, { "type": "Identifier", "start": 1394, "end": 1404, "loc": { "start": { "line": 32, "column": 26 }, "end": { "line": 32, "column": 36 }, "identifierName": "progressCB" }, "name": "progressCB" } ], "body": { "type": "BlockStatement", "start": 1405, "end": 1577, "loc": { "start": { "line": 32, "column": 37 }, "end": { "line": 35, "column": 5 } }, "body": [ { "type": "ReturnStatement", "start": 1415, "end": 1571, "loc": { "start": { "line": 33, "column": 8 }, "end": { "line": 34, "column": 48 } }, "argument": { "type": "CallExpression", "start": 1422, "end": 1570, "loc": { "start": { "line": 33, "column": 15 }, "end": { "line": 34, "column": 47 } }, "callee": { "type": "MemberExpression", "start": 1422, "end": 1540, "loc": { "start": { "line": 33, "column": 15 }, "end": { "line": 34, "column": 17 } }, "object": { "type": "CallExpression", "start": 1422, "end": 1522, "loc": { "start": { "line": 33, "column": 15 }, "end": { "line": 33, "column": 115 } }, "callee": { "type": "MemberExpression", "start": 1422, "end": 1452, "loc": { "start": { "line": 33, "column": 15 }, "end": { "line": 33, "column": 45 } }, "object": { "type": "Identifier", "start": 1422, "end": 1434, "loc": { "start": { "line": 33, "column": 15 }, "end": { "line": 33, "column": 27 }, "identifierName": "EthersWallet" }, "name": "EthersWallet" }, "property": { "type": "Identifier", "start": 1435, "end": 1452, "loc": { "start": { "line": 33, "column": 28 }, "end": { "line": 33, "column": 45 }, "identifierName": "fromEncryptedJson" }, "name": "fromEncryptedJson" }, "computed": false }, "arguments": [ { "type": "CallExpression", "start": 1453, "end": 1500, "loc": { "start": { "line": 33, "column": 46 }, "end": { "line": 33, "column": 93 } }, "callee": { "type": "MemberExpression", "start": 1453, "end": 1485, "loc": { "start": { "line": 33, "column": 46 }, "end": { "line": 33, "column": 78 } }, "object": { "type": "MemberExpression", "start": 1453, "end": 1477, "loc": { "start": { "line": 33, "column": 46 }, "end": { "line": 33, "column": 70 } }, "object": { "type": "MemberExpression", "start": 1453, "end": 1464, "loc": { "start": { "line": 33, "column": 46 }, "end": { "line": 33, "column": 57 } }, "object": { "type": "ThisExpression", "start": 1453, "end": 1457, "loc": { "start": { "line": 33, "column": 46 }, "end": { "line": 33, "column": 50 } } }, "property": { "type": "Identifier", "start": 1458, "end": 1464, "loc": { "start": { "line": 33, "column": 51 }, "end": { "line": 33, "column": 57 }, "identifierName": "window" }, "name": "window" }, "computed": false }, "property": { "type": "Identifier", "start": 1465, "end": 1477, "loc": { "start": { "line": 33, "column": 58 }, "end": { "line": 33, "column": 70 }, "identifierName": "localStorage" }, "name": "localStorage" }, "computed": false }, "property": { "type": "Identifier", "start": 1478, "end": 1485, "loc": { "start": { "line": 33, "column": 71 }, "end": { "line": 33, "column": 78 }, "identifierName": "getItem" }, "name": "getItem" }, "computed": false }, "arguments": [ { "type": "StringLiteral", "start": 1486, "end": 1499, "loc": { "start": { "line": 33, "column": 79 }, "end": { "line": 33, "column": 92 } }, "extra": { "rawValue": "localwallet", "raw": "'localwallet'" }, "value": "localwallet" } ] }, { "type": "Identifier", "start": 1502, "end": 1509, "loc": { "start": { "line": 33, "column": 95 }, "end": { "line": 33, "column": 102 }, "identifierName": "passkey" }, "name": "passkey" }, { "type": "Identifier", "start": 1511, "end": 1521, "loc": { "start": { "line": 33, "column": 104 }, "end": { "line": 33, "column": 114 }, "identifierName": "progressCB" }, "name": "progressCB" } ] }, "property": { "type": "Identifier", "start": 1536, "end": 1540, "loc": { "start": { "line": 34, "column": 13 }, "end": { "line": 34, "column": 17 }, "identifierName": "then" }, "name": "then" }, "computed": false }, "arguments": [ { "type": "ArrowFunctionExpression", "start": 1541, "end": 1569, "loc": { "start": { "line": 34, "column": 18 }, "end": { "line": 34, "column": 46 }