@alephium/web3 0.0.3 → 0.1.0-rc.2

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.
Files changed (144) hide show
  1. package/.editorconfig +13 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +21 -0
  4. package/README.md +2 -2
  5. package/contracts/add.ral +7 -3
  6. package/contracts/greeter.ral +3 -1
  7. package/contracts/greeter_interface.ral +3 -0
  8. package/contracts/greeter_main.ral +9 -0
  9. package/contracts/main.ral +3 -5
  10. package/dev/user.conf +8 -4
  11. package/dist/alephium-web3.min.js +1 -1
  12. package/dist/alephium-web3.min.js.map +1 -1
  13. package/dist/scripts/check-versions.d.ts +1 -0
  14. package/dist/scripts/check-versions.js +39 -0
  15. package/dist/{cli → scripts}/create-project.d.ts +0 -0
  16. package/dist/scripts/create-project.js +124 -0
  17. package/dist/scripts/header.d.ts +0 -0
  18. package/dist/scripts/header.js +18 -0
  19. package/dist/scripts/rename-gitignore.d.ts +1 -0
  20. package/dist/scripts/rename-gitignore.js +24 -0
  21. package/dist/scripts/start-devnet.d.ts +1 -0
  22. package/dist/scripts/start-devnet.js +131 -0
  23. package/dist/scripts/stop-devnet.d.ts +1 -0
  24. package/dist/scripts/stop-devnet.js +32 -0
  25. package/dist/{api → src/api}/api-alephium.d.ts +287 -168
  26. package/dist/{api → src/api}/api-alephium.js +497 -115
  27. package/dist/{api → src/api}/api-explorer.d.ts +117 -19
  28. package/dist/{api → src/api}/api-explorer.js +206 -46
  29. package/dist/src/api/index.d.ts +10 -0
  30. package/dist/src/api/index.js +55 -0
  31. package/dist/{lib → src}/constants.d.ts +0 -0
  32. package/dist/{lib → src}/constants.js +0 -0
  33. package/dist/src/contract/contract.d.ts +182 -0
  34. package/dist/src/contract/contract.js +760 -0
  35. package/dist/src/contract/events.d.ts +29 -0
  36. package/dist/src/contract/events.js +77 -0
  37. package/dist/src/contract/index.d.ts +3 -0
  38. package/dist/src/contract/index.js +32 -0
  39. package/dist/src/contract/ralph.d.ts +12 -0
  40. package/dist/src/contract/ralph.js +362 -0
  41. package/dist/src/index.d.ts +5 -0
  42. package/dist/src/index.js +34 -0
  43. package/dist/src/signer/index.d.ts +2 -0
  44. package/dist/src/signer/index.js +31 -0
  45. package/dist/src/signer/node-wallet.d.ts +13 -0
  46. package/dist/src/signer/node-wallet.js +60 -0
  47. package/dist/src/signer/signer.d.ts +143 -0
  48. package/dist/src/signer/signer.js +184 -0
  49. package/dist/src/test/index.d.ts +7 -0
  50. package/dist/src/test/index.js +41 -0
  51. package/dist/src/test/privatekey-wallet.d.ts +12 -0
  52. package/dist/src/test/privatekey-wallet.js +68 -0
  53. package/dist/{lib → src/utils}/address.d.ts +0 -0
  54. package/dist/{lib → src/utils}/address.js +1 -1
  55. package/dist/{lib → src/utils}/bs58.d.ts +2 -2
  56. package/dist/{lib → src/utils}/bs58.js +3 -1
  57. package/dist/{lib → src/utils}/djb2.d.ts +0 -0
  58. package/dist/{lib → src/utils}/djb2.js +1 -1
  59. package/dist/src/utils/index.d.ts +6 -0
  60. package/dist/src/utils/index.js +35 -0
  61. package/dist/{lib → src/utils}/password-crypto.d.ts +0 -0
  62. package/dist/{lib → src/utils}/password-crypto.js +8 -7
  63. package/dist/src/utils/transaction.d.ts +2 -0
  64. package/dist/src/utils/transaction.js +58 -0
  65. package/dist/src/utils/utils.d.ts +30 -0
  66. package/dist/{lib → src/utils}/utils.js +83 -19
  67. package/gitignore +5 -4
  68. package/package.json +55 -41
  69. package/scripts/create-project.ts +136 -0
  70. package/scripts/header.js +17 -0
  71. package/scripts/start-devnet.js +3 -3
  72. package/src/api/api-alephium.ts +2323 -0
  73. package/src/api/api-explorer.ts +808 -0
  74. package/src/api/index.ts +35 -0
  75. package/src/constants.ts +20 -0
  76. package/src/contract/contract.ts +1014 -0
  77. package/src/contract/events.ts +102 -0
  78. package/src/contract/index.ts +21 -0
  79. package/src/contract/ralph.test.ts +178 -0
  80. package/src/contract/ralph.ts +362 -0
  81. package/src/fixtures/address.json +36 -0
  82. package/src/fixtures/balance.json +9 -0
  83. package/src/fixtures/self-clique.json +19 -0
  84. package/src/fixtures/transaction.json +13 -0
  85. package/src/fixtures/transactions.json +179 -0
  86. package/src/index.ts +24 -0
  87. package/src/signer/fixtures/genesis.json +26 -0
  88. package/src/signer/fixtures/wallets.json +26 -0
  89. package/src/signer/index.ts +20 -0
  90. package/src/signer/node-wallet.ts +74 -0
  91. package/src/signer/signer.ts +313 -0
  92. package/src/test/index.ts +32 -0
  93. package/src/test/privatekey-wallet.ts +58 -0
  94. package/src/utils/address.test.ts +47 -0
  95. package/src/utils/address.ts +39 -0
  96. package/src/utils/bs58.ts +26 -0
  97. package/src/utils/djb2.test.ts +35 -0
  98. package/src/utils/djb2.ts +25 -0
  99. package/src/utils/index.ts +24 -0
  100. package/src/utils/password-crypto.test.ts +27 -0
  101. package/src/utils/password-crypto.ts +77 -0
  102. package/src/utils/transaction.test.ts +50 -0
  103. package/src/utils/transaction.ts +39 -0
  104. package/src/utils/utils.test.ts +160 -0
  105. package/src/utils/utils.ts +209 -0
  106. package/templates/{README.md → base/README.md} +4 -4
  107. package/templates/base/package.json +35 -0
  108. package/templates/base/src/greeter.ts +41 -0
  109. package/templates/base/tsconfig.json +19 -0
  110. package/templates/react/README.md +34 -0
  111. package/templates/react/config-overrides.js +18 -0
  112. package/templates/react/package.json +66 -0
  113. package/templates/react/src/App.tsx +42 -0
  114. package/templates/react/src/artifacts/greeter.ral.json +26 -0
  115. package/templates/react/src/artifacts/greeter_main.ral.json +22 -0
  116. package/templates/shared/.eslintrc.json +12 -0
  117. package/templates/shared/scripts/header.js +0 -0
  118. package/test/contract.test.ts +161 -0
  119. package/test/events.test.ts +139 -0
  120. package/webpack.config.js +1 -1
  121. package/contracts/greeter-main.ral +0 -8
  122. package/dist/cli/create-project.js +0 -87
  123. package/dist/lib/clique.d.ts +0 -23
  124. package/dist/lib/clique.js +0 -149
  125. package/dist/lib/contract.d.ts +0 -152
  126. package/dist/lib/contract.js +0 -711
  127. package/dist/lib/explorer.d.ts +0 -8
  128. package/dist/lib/explorer.js +0 -46
  129. package/dist/lib/index.d.ts +0 -12
  130. package/dist/lib/index.js +0 -60
  131. package/dist/lib/node.d.ts +0 -10
  132. package/dist/lib/node.js +0 -64
  133. package/dist/lib/numbers.d.ts +0 -7
  134. package/dist/lib/numbers.js +0 -128
  135. package/dist/lib/signer.d.ts +0 -17
  136. package/dist/lib/signer.js +0 -70
  137. package/dist/lib/storage-browser.d.ts +0 -9
  138. package/dist/lib/storage-browser.js +0 -52
  139. package/dist/lib/storage-node.d.ts +0 -9
  140. package/dist/lib/storage-node.js +0 -65
  141. package/dist/lib/utils.d.ts +0 -11
  142. package/dist/lib/wallet.d.ts +0 -30
  143. package/dist/lib/wallet.js +0 -142
  144. package/templates/package.json +0 -29
@@ -1,8 +0,0 @@
1
- import { Api } from '../api/api-explorer';
2
- /**
3
- * Explorer client
4
- */
5
- export declare class ExplorerClient extends Api<null> {
6
- getAddressTransactions(address: string, page: number): Promise<import("../api/api-explorer").HttpResponse<import("../api/api-explorer").Transaction[], import("../api/api-explorer").BadRequest | import("../api/api-explorer").InternalServerError | import("../api/api-explorer").NotFound | import("../api/api-explorer").ServiceUnavailable | import("../api/api-explorer").Unauthorized>>;
7
- getAddressDetails(address: string): Promise<import("../api/api-explorer").HttpResponse<import("../api/api-explorer").AddressInfo, import("../api/api-explorer").BadRequest | import("../api/api-explorer").InternalServerError | import("../api/api-explorer").NotFound | import("../api/api-explorer").ServiceUnavailable | import("../api/api-explorer").Unauthorized>>;
8
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright 2018 - 2022 The Alephium Authors
4
- This file is part of the alephium project.
5
-
6
- The library is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- The library is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with the library. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
20
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
- return new (P || (P = Promise))(function (resolve, reject) {
22
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
23
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
24
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
25
- step((generator = generator.apply(thisArg, _arguments || [])).next());
26
- });
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.ExplorerClient = void 0;
30
- const api_explorer_1 = require("../api/api-explorer");
31
- /**
32
- * Explorer client
33
- */
34
- class ExplorerClient extends api_explorer_1.Api {
35
- getAddressTransactions(address, page) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- return yield this.addresses.getAddressesAddressTransactions(address, { page });
38
- });
39
- }
40
- getAddressDetails(address) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- return yield this.addresses.getAddressesAddress(address);
43
- });
44
- }
45
- }
46
- exports.ExplorerClient = ExplorerClient;
@@ -1,12 +0,0 @@
1
- export * from './clique';
2
- export * from './node';
3
- export * from './utils';
4
- export * from './wallet';
5
- export * from './explorer';
6
- export * from './address';
7
- export * from './signer';
8
- export * from './contract';
9
- export { formatAmountForDisplay, calAmountDelta, convertAlphToSet, addApostrophes, convertSetToAlph, BILLION } from './numbers';
10
- export * from './constants';
11
- export * as node from '../api/api-alephium';
12
- export * as explorer from '../api/api-explorer';
package/dist/lib/index.js DELETED
@@ -1,60 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright 2018 - 2022 The Alephium Authors
4
- This file is part of the alephium project.
5
-
6
- The library is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- The library is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with the library. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
- if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
22
- }) : (function(o, m, k, k2) {
23
- if (k2 === undefined) k2 = k;
24
- o[k2] = m[k];
25
- }));
26
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
27
- Object.defineProperty(o, "default", { enumerable: true, value: v });
28
- }) : function(o, v) {
29
- o["default"] = v;
30
- });
31
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
32
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
33
- };
34
- var __importStar = (this && this.__importStar) || function (mod) {
35
- if (mod && mod.__esModule) return mod;
36
- var result = {};
37
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
38
- __setModuleDefault(result, mod);
39
- return result;
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.explorer = exports.node = exports.BILLION = exports.convertSetToAlph = exports.addApostrophes = exports.convertAlphToSet = exports.calAmountDelta = exports.formatAmountForDisplay = void 0;
43
- __exportStar(require("./clique"), exports);
44
- __exportStar(require("./node"), exports);
45
- __exportStar(require("./utils"), exports);
46
- __exportStar(require("./wallet"), exports);
47
- __exportStar(require("./explorer"), exports);
48
- __exportStar(require("./address"), exports);
49
- __exportStar(require("./signer"), exports);
50
- __exportStar(require("./contract"), exports);
51
- var numbers_1 = require("./numbers");
52
- Object.defineProperty(exports, "formatAmountForDisplay", { enumerable: true, get: function () { return numbers_1.formatAmountForDisplay; } });
53
- Object.defineProperty(exports, "calAmountDelta", { enumerable: true, get: function () { return numbers_1.calAmountDelta; } });
54
- Object.defineProperty(exports, "convertAlphToSet", { enumerable: true, get: function () { return numbers_1.convertAlphToSet; } });
55
- Object.defineProperty(exports, "addApostrophes", { enumerable: true, get: function () { return numbers_1.addApostrophes; } });
56
- Object.defineProperty(exports, "convertSetToAlph", { enumerable: true, get: function () { return numbers_1.convertSetToAlph; } });
57
- Object.defineProperty(exports, "BILLION", { enumerable: true, get: function () { return numbers_1.BILLION; } });
58
- __exportStar(require("./constants"), exports);
59
- exports.node = __importStar(require("../api/api-alephium"));
60
- exports.explorer = __importStar(require("../api/api-explorer"));
@@ -1,10 +0,0 @@
1
- import { Api } from '../api/api-alephium';
2
- /**
3
- * Node client
4
- */
5
- export declare class NodeClient extends Api<null> {
6
- getBalance(address: string): Promise<import("../api/api-alephium").HttpResponse<import("../api/api-alephium").Balance, import("../api/api-alephium").BadRequest | import("../api/api-alephium").InternalServerError | import("../api/api-alephium").NotFound | import("../api/api-alephium").ServiceUnavailable | import("../api/api-alephium").Unauthorized>>;
7
- transactionCreate(fromPublicKey: string, toAddress: string, amount: string, lockTime?: number, gas?: number, gasPrice?: string): Promise<import("../api/api-alephium").HttpResponse<import("../api/api-alephium").BuildTransactionResult, import("../api/api-alephium").BadRequest | import("../api/api-alephium").InternalServerError | import("../api/api-alephium").NotFound | import("../api/api-alephium").ServiceUnavailable | import("../api/api-alephium").Unauthorized>>;
8
- transactionConsolidateUTXOs(fromPublicKey: string, toAddress: string): Promise<import("../api/api-alephium").HttpResponse<import("../api/api-alephium").BuildSweepAddressTransactionsResult, import("../api/api-alephium").BadRequest | import("../api/api-alephium").InternalServerError | import("../api/api-alephium").NotFound | import("../api/api-alephium").ServiceUnavailable | import("../api/api-alephium").Unauthorized>>;
9
- transactionSend(tx: string, signature: string): Promise<import("../api/api-alephium").HttpResponse<import("../api/api-alephium").TxResult, import("../api/api-alephium").BadRequest | import("../api/api-alephium").InternalServerError | import("../api/api-alephium").NotFound | import("../api/api-alephium").ServiceUnavailable | import("../api/api-alephium").Unauthorized>>;
10
- }
package/dist/lib/node.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright 2018 - 2022 The Alephium Authors
4
- This file is part of the alephium project.
5
-
6
- The library is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- The library is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with the library. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
20
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
- return new (P || (P = Promise))(function (resolve, reject) {
22
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
23
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
24
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
25
- step((generator = generator.apply(thisArg, _arguments || [])).next());
26
- });
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.NodeClient = void 0;
30
- const api_alephium_1 = require("../api/api-alephium");
31
- /**
32
- * Node client
33
- */
34
- class NodeClient extends api_alephium_1.Api {
35
- getBalance(address) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- return yield this.addresses.getAddressesAddressBalance(address);
38
- });
39
- }
40
- transactionCreate(fromPublicKey, toAddress, amount, lockTime, gas, gasPrice) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- return yield this.transactions.postTransactionsBuild({
43
- fromPublicKey,
44
- destinations: [{ address: toAddress, alphAmount: amount, lockTime }],
45
- gas,
46
- gasPrice
47
- });
48
- });
49
- }
50
- transactionConsolidateUTXOs(fromPublicKey, toAddress) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- return yield this.transactions.postTransactionsSweepAddressBuild({
53
- fromPublicKey,
54
- toAddress
55
- });
56
- });
57
- }
58
- transactionSend(tx, signature) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- return yield this.transactions.postTransactionsSubmit({ unsignedTx: tx, signature });
61
- });
62
- }
63
- }
64
- exports.NodeClient = NodeClient;
@@ -1,7 +0,0 @@
1
- import { Transaction } from '../api/api-explorer';
2
- export declare const BILLION = 1000000000;
3
- export declare const formatAmountForDisplay: (baseNum: bigint, showFullPrecision?: boolean, nbOfDecimalsToShow?: number | undefined) => string;
4
- export declare const calAmountDelta: (t: Transaction, id: string) => bigint;
5
- export declare const convertAlphToSet: (amount: string) => bigint;
6
- export declare const addApostrophes: (numString: string) => string;
7
- export declare const convertSetToAlph: (amountInSet: bigint) => string;
@@ -1,128 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright 2018 - 2022 The Alephium Authors
4
- This file is part of the alephium project.
5
-
6
- The library is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- The library is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with the library. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.convertSetToAlph = exports.addApostrophes = exports.convertAlphToSet = exports.calAmountDelta = exports.formatAmountForDisplay = exports.BILLION = void 0;
21
- const MONEY_SYMBOL = ['', 'K', 'M', 'B', 'T'];
22
- const QUINTILLION = 1000000000000000000;
23
- const NUM_OF_ZEROS_IN_QUINTILLION = 18;
24
- exports.BILLION = 1000000000;
25
- const produceZeros = (numberOfZeros) => '0'.repeat(numberOfZeros);
26
- const getNumberOfTrailingZeros = (numString) => {
27
- let numberOfZeros = 0;
28
- for (let i = numString.length - 1; i >= 0; i--) {
29
- if (numString[i] === '0') {
30
- numberOfZeros++;
31
- }
32
- else {
33
- break;
34
- }
35
- }
36
- return numberOfZeros;
37
- };
38
- const removeTrailingZeros = (numString, minNumberOfDecimals) => {
39
- const numberOfZeros = getNumberOfTrailingZeros(numString);
40
- const numStringWithoutTrailingZeros = numString.substring(0, numString.length - numberOfZeros);
41
- if (!minNumberOfDecimals)
42
- return numStringWithoutTrailingZeros.endsWith('.')
43
- ? numStringWithoutTrailingZeros.slice(0, -1)
44
- : numStringWithoutTrailingZeros;
45
- if (minNumberOfDecimals < 0)
46
- throw 'minNumberOfDecimals should be positive';
47
- const indexOfPoint = numStringWithoutTrailingZeros.indexOf('.');
48
- if (indexOfPoint === -1)
49
- throw 'numString should contain decimal point';
50
- const numberOfDecimals = numStringWithoutTrailingZeros.length - 1 - indexOfPoint;
51
- return numberOfDecimals < minNumberOfDecimals
52
- ? numStringWithoutTrailingZeros.concat(produceZeros(minNumberOfDecimals - numberOfDecimals))
53
- : numStringWithoutTrailingZeros;
54
- };
55
- const formatAmountForDisplay = (baseNum, showFullPrecision = false, nbOfDecimalsToShow) => {
56
- if (baseNum < BigInt(0))
57
- return '???';
58
- // For abbreviation, we don't need full precision and can work with number
59
- const alphNum = Number(baseNum) / QUINTILLION;
60
- const minNumberOfDecimals = alphNum >= 0.000005 && alphNum < 0.01 ? 3 : 2;
61
- const numberOfDecimalsToDisplay = nbOfDecimalsToShow || minNumberOfDecimals;
62
- if (showFullPrecision) {
63
- const baseNumString = baseNum.toString();
64
- const numNonDecimals = baseNumString.length - NUM_OF_ZEROS_IN_QUINTILLION;
65
- const alphNumString = numNonDecimals > 0
66
- ? baseNumString.substring(0, numNonDecimals).concat('.', baseNumString.substring(numNonDecimals))
67
- : '0.'.concat(produceZeros(-numNonDecimals), baseNumString);
68
- return removeTrailingZeros(alphNumString, numberOfDecimalsToDisplay);
69
- }
70
- if (alphNum < 0.001) {
71
- const tinyAmountsMaxNumberDecimals = 5;
72
- return removeTrailingZeros(alphNum.toFixed(tinyAmountsMaxNumberDecimals), minNumberOfDecimals);
73
- }
74
- else if (alphNum <= 1000000) {
75
- return (0, exports.addApostrophes)(removeTrailingZeros(alphNum.toFixed(numberOfDecimalsToDisplay), minNumberOfDecimals));
76
- }
77
- const tier = alphNum < 1000000000 ? 2 : alphNum < 1000000000000 ? 3 : 4;
78
- // get suffix and determine scale
79
- const suffix = MONEY_SYMBOL[tier];
80
- const scale = Math.pow(10, tier * 3);
81
- // Scale the bigNum
82
- // Here we need to be careful of precision issues
83
- const scaled = alphNum / scale;
84
- return scaled.toFixed(numberOfDecimalsToDisplay) + suffix;
85
- };
86
- exports.formatAmountForDisplay = formatAmountForDisplay;
87
- const calAmountDelta = (t, id) => {
88
- if (!t.inputs || !t.outputs) {
89
- throw 'Missing transaction details';
90
- }
91
- const inputAmount = t.inputs.reduce((acc, input) => {
92
- return input.amount && input.address === id ? acc + BigInt(input.amount) : acc;
93
- }, BigInt(0));
94
- const outputAmount = t.outputs.reduce((acc, output) => {
95
- return output.address === id ? acc + BigInt(output.amount) : acc;
96
- }, BigInt(0));
97
- return outputAmount - inputAmount;
98
- };
99
- exports.calAmountDelta = calAmountDelta;
100
- const convertAlphToSet = (amount) => {
101
- if (!isNumber(amount) || Number(amount) < 0)
102
- throw 'Invalid Alph amount';
103
- if (amount === '0')
104
- return BigInt(0);
105
- const numberOfDecimals = amount.includes('.') ? amount.length - 1 - amount.indexOf('.') : 0;
106
- const numberOfZerosToAdd = NUM_OF_ZEROS_IN_QUINTILLION - numberOfDecimals;
107
- const cleanedAmount = amount.replace('.', '') + produceZeros(numberOfZerosToAdd);
108
- return BigInt(cleanedAmount);
109
- };
110
- exports.convertAlphToSet = convertAlphToSet;
111
- const addApostrophes = (numString) => {
112
- if (!isNumber(numString))
113
- throw 'Invalid number';
114
- return numString.replace(/\B(?=(\d{3})+(?!\d))/g, "'");
115
- };
116
- exports.addApostrophes = addApostrophes;
117
- const convertSetToAlph = (amountInSet) => {
118
- const amountInSetStr = amountInSet.toString();
119
- if (amountInSetStr === '0')
120
- return amountInSetStr;
121
- const positionForDot = amountInSetStr.length - NUM_OF_ZEROS_IN_QUINTILLION;
122
- const withDotAdded = positionForDot > 0
123
- ? amountInSetStr.substring(0, positionForDot) + '.' + amountInSetStr.substring(positionForDot)
124
- : '0.' + produceZeros(NUM_OF_ZEROS_IN_QUINTILLION - amountInSetStr.length) + amountInSetStr;
125
- return removeTrailingZeros(withDotAdded);
126
- };
127
- exports.convertSetToAlph = convertSetToAlph;
128
- const isNumber = (numString) => !Number.isNaN(Number(numString)) && numString.length > 0 && !numString.includes('e');
@@ -1,17 +0,0 @@
1
- import { CliqueClient } from './clique';
2
- export declare class Signer {
3
- client: CliqueClient;
4
- walletName: string;
5
- address: string;
6
- private _publicKey?;
7
- constructor(client: CliqueClient, walletName: string, address: string);
8
- static testSigner(client: CliqueClient): Signer;
9
- getPublicKey(): Promise<string>;
10
- sign(hash: string): Promise<string>;
11
- submitTransaction(unsignedTx: string, txHash: string): Promise<SubmissionResult>;
12
- }
13
- export interface SubmissionResult {
14
- txId: string;
15
- fromGroup: number;
16
- toGroup: number;
17
- }
@@ -1,70 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright 2018 - 2022 The Alephium Authors
4
- This file is part of the alephium project.
5
-
6
- The library is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- The library is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with the library. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
20
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
- return new (P || (P = Promise))(function (resolve, reject) {
22
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
23
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
24
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
25
- step((generator = generator.apply(thisArg, _arguments || [])).next());
26
- });
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Signer = void 0;
30
- const clique_1 = require("./clique");
31
- class Signer {
32
- constructor(client, walletName, address) {
33
- this.client = client;
34
- this.walletName = walletName;
35
- this.address = address;
36
- }
37
- static testSigner(client) {
38
- return new Signer(client, 'alephium-js-sdk-test-only-wallet', '12LgGdbjE6EtnTKw5gdBwV2RRXuXPtzYM7SDZ45YJTRht');
39
- }
40
- getPublicKey() {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- if (this._publicKey) {
43
- return this._publicKey;
44
- }
45
- else {
46
- const response = yield this.client.wallets.getWalletsWalletNameAddressesAddress(this.walletName, this.address);
47
- this._publicKey = clique_1.CliqueClient.convert(response).publicKey;
48
- return this._publicKey;
49
- }
50
- });
51
- }
52
- sign(hash) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const response = yield this.client.wallets.postWalletsWalletNameSign(this.walletName, { data: hash });
55
- return clique_1.CliqueClient.convert(response).signature;
56
- });
57
- }
58
- submitTransaction(unsignedTx, txHash) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const signature = yield this.sign(txHash);
61
- const params = { unsignedTx: unsignedTx, signature: signature };
62
- const response = yield this.client.transactions.postTransactionsSubmit(params);
63
- return fromApiSubmissionResult(clique_1.CliqueClient.convert(response));
64
- });
65
- }
66
- }
67
- exports.Signer = Signer;
68
- function fromApiSubmissionResult(result) {
69
- return result;
70
- }
@@ -1,9 +0,0 @@
1
- declare class BrowserStorage {
2
- key: string;
3
- constructor();
4
- remove: (name: string) => void;
5
- load: (name: string) => any;
6
- save: (name: string, json: unknown) => void;
7
- list: () => string[];
8
- }
9
- export default BrowserStorage;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright 2018 - 2022 The Alephium Authors
4
- This file is part of the alephium project.
5
-
6
- The library is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- The library is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with the library. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- class BrowserStorage {
21
- constructor() {
22
- this.remove = (name) => {
23
- window.localStorage.removeItem(`${this.key}-${name}`);
24
- };
25
- this.load = (name) => {
26
- const str = window.localStorage.getItem(`${this.key}-${name}`);
27
- if (str) {
28
- return JSON.parse(str);
29
- }
30
- else {
31
- throw new Error(`Unable to load wallet ${name}`);
32
- }
33
- };
34
- this.save = (name, json) => {
35
- const str = JSON.stringify(json);
36
- window.localStorage.setItem(`${this.key}-${name}`, str);
37
- };
38
- this.list = () => {
39
- const prefixLen = this.key.length + 1;
40
- const xs = [];
41
- for (let i = 0, len = localStorage.length; i < len; ++i) {
42
- const key = localStorage.key(i);
43
- if (key && key.startsWith(this.key)) {
44
- xs.push(key.substring(prefixLen));
45
- }
46
- }
47
- return xs;
48
- };
49
- this.key = 'wallet';
50
- }
51
- }
52
- exports.default = BrowserStorage;
@@ -1,9 +0,0 @@
1
- declare class NodeStorage {
2
- walletsUrl: string;
3
- constructor();
4
- remove: (name: string) => void;
5
- load: (name: string) => any;
6
- save: (name: string, json: unknown) => void;
7
- list: () => string[];
8
- }
9
- export default NodeStorage;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright 2018 - 2022 The Alephium Authors
4
- This file is part of the alephium project.
5
-
6
- The library is free software: you can redistribute it and/or modify
7
- it under the terms of the GNU Lesser General Public License as published by
8
- the Free Software Foundation, either version 3 of the License, or
9
- (at your option) any later version.
10
-
11
- The library is distributed in the hope that it will be useful,
12
- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- GNU Lesser General Public License for more details.
15
-
16
- You should have received a copy of the GNU Lesser General Public License
17
- along with the library. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
- var __importDefault = (this && this.__importDefault) || function (mod) {
20
- return (mod && mod.__esModule) ? mod : { "default": mod };
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- const fs_1 = __importDefault(require("fs"));
24
- class NodeStorage {
25
- constructor() {
26
- this.remove = (name) => {
27
- fs_1.default.unlinkSync(this.walletsUrl + '/' + name + '.dat');
28
- };
29
- this.load = (name) => {
30
- let buffer;
31
- try {
32
- buffer = fs_1.default.readFileSync(this.walletsUrl + '/' + name + '.dat');
33
- }
34
- catch (error) {
35
- throw new Error(`Unable to load wallet ${name}: ${error}`);
36
- }
37
- return JSON.parse(buffer.toString());
38
- };
39
- this.save = (name, json) => {
40
- const str = JSON.stringify(json);
41
- const data = new Uint8Array(Buffer.from(str));
42
- fs_1.default.writeFileSync(this.walletsUrl.toString() + '/' + name + '.dat', data);
43
- };
44
- this.list = () => {
45
- const xs = [];
46
- try {
47
- const files = fs_1.default.readdirSync(this.walletsUrl);
48
- files.forEach(function (file) {
49
- if (file.endsWith('.dat')) {
50
- xs.push(file.substring(0, file.length - 4));
51
- }
52
- });
53
- }
54
- catch (e) {
55
- return [];
56
- }
57
- return xs;
58
- };
59
- this.walletsUrl = process.env.HOME + '/.alephium-wallet-apps';
60
- if (!fs_1.default.existsSync(this.walletsUrl)) {
61
- fs_1.default.mkdirSync(this.walletsUrl);
62
- }
63
- }
64
- }
65
- exports.default = NodeStorage;
@@ -1,11 +0,0 @@
1
- import * as EC from 'elliptic';
2
- import NodeStorage from './storage-node';
3
- import BrowserStorage from './storage-browser';
4
- export declare const signatureEncode: (ec: EC.ec, signature: EC.ec.Signature) => string;
5
- export declare const signatureDecode: (ec: EC.ec, signature: string) => {
6
- r: string;
7
- s: string;
8
- };
9
- export declare const getStorage: () => BrowserStorage | NodeStorage;
10
- export declare const groupOfAddress: (address: string) => number;
11
- export declare function tokenIdFromAddress(address: string): string;
@@ -1,30 +0,0 @@
1
- /// <reference types="node" />
2
- declare type WalletProps = {
3
- address: string;
4
- publicKey: string;
5
- privateKey: string;
6
- seed: Buffer;
7
- mnemonic: string;
8
- };
9
- export declare class Wallet {
10
- readonly address: string;
11
- readonly publicKey: string;
12
- readonly privateKey: string;
13
- readonly seed: Buffer;
14
- readonly mnemonic: string;
15
- constructor({ address, publicKey, privateKey, seed, mnemonic }: WalletProps);
16
- encrypt: (password: string) => string;
17
- }
18
- export declare const getPath: (addressIndex?: number | undefined) => string;
19
- export declare const getWalletFromMnemonic: (mnemonic: string) => Wallet;
20
- export declare type AddressAndKeys = {
21
- address: string;
22
- publicKey: string;
23
- privateKey: string;
24
- addressIndex: number;
25
- };
26
- export declare const deriveNewAddressData: (seed: Buffer, forGroup?: number | undefined, addressIndex?: number | undefined, skipAddressIndexes?: number[]) => AddressAndKeys;
27
- export declare const walletGenerate: () => Wallet;
28
- export declare const walletImport: (mnemonic: string) => Wallet;
29
- export declare const walletOpen: (password: string, encryptedWallet: string) => Wallet;
30
- export {};