@alephium/web3 0.2.0-rc.0 → 0.2.0-rc.11

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 (98) hide show
  1. package/.eslintignore +2 -2
  2. package/README.md +2 -135
  3. package/contracts/greeter/greeter.ral +3 -3
  4. package/contracts/greeter/greeter_interface.ral +1 -0
  5. package/contracts/greeter_main.ral +3 -5
  6. package/dist/alephium-web3.min.js +1 -1
  7. package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
  8. package/dist/alephium-web3.min.js.map +1 -1
  9. package/dist/scripts/create-project.js +3 -2
  10. package/dist/src/api/api-alephium.d.ts +46 -13
  11. package/dist/src/api/api-alephium.js +19 -3
  12. package/dist/src/api/api-explorer.d.ts +32 -16
  13. package/dist/src/api/api-explorer.js +26 -0
  14. package/dist/src/api/index.d.ts +3 -2
  15. package/dist/src/api/index.js +22 -3
  16. package/dist/src/api/types.d.ts +23 -0
  17. package/dist/src/api/types.js +240 -0
  18. package/dist/src/contract/contract.d.ts +104 -64
  19. package/dist/src/contract/contract.js +370 -426
  20. package/dist/src/contract/events.d.ts +4 -4
  21. package/dist/src/contract/index.js +5 -1
  22. package/dist/src/contract/ralph.d.ts +4 -4
  23. package/dist/src/global.d.ts +4 -0
  24. package/dist/src/global.js +38 -0
  25. package/dist/src/index.d.ts +2 -0
  26. package/dist/src/index.js +20 -1
  27. package/dist/src/signer/index.d.ts +0 -1
  28. package/dist/src/signer/index.js +5 -2
  29. package/dist/src/signer/signer.d.ts +21 -11
  30. package/dist/src/signer/signer.js +46 -9
  31. package/dist/src/transaction/index.d.ts +0 -1
  32. package/dist/src/transaction/index.js +5 -2
  33. package/dist/src/transaction/status.d.ts +2 -1
  34. package/dist/src/utils/index.d.ts +0 -1
  35. package/dist/src/utils/index.js +5 -2
  36. package/dist/src/utils/subscription.d.ts +0 -1
  37. package/dist/src/utils/subscription.js +2 -1
  38. package/dist/src/utils/utils.d.ts +5 -4
  39. package/dist/src/utils/utils.js +18 -17
  40. package/jest-config.json +11 -0
  41. package/package.json +7 -35
  42. package/scripts/create-project.ts +3 -2
  43. package/src/api/api-alephium.ts +56 -8
  44. package/src/api/api-explorer.ts +30 -0
  45. package/src/api/index.ts +14 -3
  46. package/src/api/types.ts +233 -0
  47. package/src/contract/contract.ts +537 -526
  48. package/src/contract/events.ts +6 -6
  49. package/src/contract/ralph.ts +4 -4
  50. package/src/{transaction/sign-verify.ts → global.ts} +14 -15
  51. package/src/index.ts +3 -0
  52. package/src/signer/index.ts +0 -1
  53. package/src/signer/signer.ts +70 -19
  54. package/src/transaction/index.ts +0 -1
  55. package/src/transaction/status.ts +4 -2
  56. package/src/utils/index.ts +0 -1
  57. package/src/utils/subscription.ts +3 -3
  58. package/src/utils/utils.ts +11 -11
  59. package/templates/base/package.json +2 -2
  60. package/templates/base/src/greeter.ts +10 -9
  61. package/templates/react/package.json +2 -2
  62. package/templates/react/src/App.tsx +2 -2
  63. package/.eslintrc.json +0 -21
  64. package/LICENSE +0 -165
  65. package/contracts/add/add.ral +0 -16
  66. package/contracts/main.ral +0 -6
  67. package/contracts/sub/sub.ral +0 -9
  68. package/dist/src/signer/node-wallet.d.ts +0 -13
  69. package/dist/src/signer/node-wallet.js +0 -60
  70. package/dist/src/test/index.d.ts +0 -7
  71. package/dist/src/test/index.js +0 -41
  72. package/dist/src/test/privatekey-wallet.d.ts +0 -12
  73. package/dist/src/test/privatekey-wallet.js +0 -68
  74. package/dist/src/transaction/sign-verify.d.ts +0 -2
  75. package/dist/src/transaction/sign-verify.js +0 -58
  76. package/dist/src/utils/password-crypto.d.ts +0 -2
  77. package/dist/src/utils/password-crypto.js +0 -69
  78. package/gitignore +0 -10
  79. package/src/contract/ralph.test.ts +0 -178
  80. package/src/fixtures/address.json +0 -36
  81. package/src/fixtures/balance.json +0 -9
  82. package/src/fixtures/self-clique.json +0 -19
  83. package/src/fixtures/transaction.json +0 -13
  84. package/src/fixtures/transactions.json +0 -179
  85. package/src/signer/fixtures/genesis.json +0 -26
  86. package/src/signer/fixtures/wallets.json +0 -26
  87. package/src/signer/node-wallet.ts +0 -74
  88. package/src/test/index.ts +0 -32
  89. package/src/test/privatekey-wallet.ts +0 -58
  90. package/src/transaction/sign-verify.test.ts +0 -50
  91. package/src/utils/address.test.ts +0 -47
  92. package/src/utils/djb2.test.ts +0 -35
  93. package/src/utils/password-crypto.test.ts +0 -27
  94. package/src/utils/password-crypto.ts +0 -77
  95. package/src/utils/utils.test.ts +0 -161
  96. package/test/contract.test.ts +0 -178
  97. package/test/events.test.ts +0 -138
  98. package/test/transaction.test.ts +0 -72
@@ -1,11 +1,11 @@
1
- import { ContractEvent } from '../api/api-alephium';
1
+ import { node } from '../api';
2
2
  import { Subscription, SubscribeOptions } from '../utils';
3
- export declare class EventSubscription extends Subscription<ContractEvent> {
3
+ export declare class EventSubscription extends Subscription<node.ContractEvent> {
4
4
  readonly contractAddress: string;
5
5
  private fromCount;
6
- constructor(options: SubscribeOptions<ContractEvent>, contractAddress: string, fromCount?: number);
6
+ constructor(options: SubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number);
7
7
  startPolling(): void;
8
8
  currentEventCount(): number;
9
9
  polling(): Promise<void>;
10
10
  }
11
- export declare function subscribeToEvents(options: SubscribeOptions<ContractEvent>, contractAddress: string, fromCount?: number): EventSubscription;
11
+ export declare function subscribeToEvents(options: SubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number): EventSubscription;
@@ -18,7 +18,11 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
20
  if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
22
26
  }) : (function(o, m, k, k2) {
23
27
  if (k2 === undefined) k2 = k;
24
28
  o[k2] = m[k];
@@ -1,5 +1,5 @@
1
- import { node } from '../api';
2
- import { Fields, Val } from './contract';
1
+ import { Val } from '../api';
2
+ import { Fields, FieldsSig } from './contract';
3
3
  export declare function encodeBool(bool: boolean): Uint8Array;
4
4
  export declare function encodeI256(i256: bigint): Uint8Array;
5
5
  export declare function encodeU256(u256: bigint): Uint8Array;
@@ -7,6 +7,6 @@ export declare function encodeByteVec(bytes: string): Uint8Array;
7
7
  export declare function encodeAddress(address: string): Uint8Array;
8
8
  export declare function encodeScriptFieldAsString(tpe: string, value: Val): string;
9
9
  export declare function encodeScriptField(tpe: string, value: Val): Uint8Array;
10
- export declare function buildScriptByteCode(bytecodeTemplate: string, fields: Fields, fieldsSig: node.FieldsSig): string;
11
- export declare function buildContractByteCode(bytecode: string, fields: Fields, fieldsSig: node.FieldsSig): string;
10
+ export declare function buildScriptByteCode(bytecodeTemplate: string, fields: Fields, fieldsSig: FieldsSig): string;
11
+ export declare function buildContractByteCode(bytecode: string, fields: Fields, fieldsSig: FieldsSig): string;
12
12
  export declare function encodeContractField(tpe: string, value: Val): Uint8Array[];
@@ -0,0 +1,4 @@
1
+ import { NodeProvider } from './api';
2
+ export declare function setCurrentNodeProvider(provider: NodeProvider): void;
3
+ export declare function setCurrentNodeProvider(baseUrl: string, apiKey?: string): void;
4
+ export declare function getCurrentNodeProvider(): NodeProvider;
@@ -0,0 +1,38 @@
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.getCurrentNodeProvider = exports.setCurrentNodeProvider = void 0;
21
+ const api_1 = require("./api");
22
+ let _currentNodeProvider = undefined;
23
+ function setCurrentNodeProvider(provider, apiKey) {
24
+ if (typeof provider == 'string') {
25
+ _currentNodeProvider = new api_1.NodeProvider(provider, apiKey);
26
+ }
27
+ else {
28
+ _currentNodeProvider = provider;
29
+ }
30
+ }
31
+ exports.setCurrentNodeProvider = setCurrentNodeProvider;
32
+ function getCurrentNodeProvider() {
33
+ if (typeof _currentNodeProvider === 'undefined') {
34
+ throw Error('No node provider is set.');
35
+ }
36
+ return _currentNodeProvider;
37
+ }
38
+ exports.getCurrentNodeProvider = getCurrentNodeProvider;
@@ -4,3 +4,5 @@ export * from './signer';
4
4
  export * from './utils';
5
5
  export * from './transaction';
6
6
  export * from './constants';
7
+ export * as web3 from './global';
8
+ export * as utils from './utils';
package/dist/src/index.js CHANGED
@@ -18,18 +18,37 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
20
  if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
22
26
  }) : (function(o, m, k, k2) {
23
27
  if (k2 === undefined) k2 = k;
24
28
  o[k2] = m[k];
25
29
  }));
30
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
31
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
32
+ }) : function(o, v) {
33
+ o["default"] = v;
34
+ });
26
35
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
37
  };
38
+ var __importStar = (this && this.__importStar) || function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
29
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.utils = exports.web3 = void 0;
30
47
  __exportStar(require("./api"), exports);
31
48
  __exportStar(require("./contract"), exports);
32
49
  __exportStar(require("./signer"), exports);
33
50
  __exportStar(require("./utils"), exports);
34
51
  __exportStar(require("./transaction"), exports);
35
52
  __exportStar(require("./constants"), exports);
53
+ exports.web3 = __importStar(require("./global"));
54
+ exports.utils = __importStar(require("./utils"));
@@ -1,2 +1 @@
1
1
  export * from './signer';
2
- export * from './node-wallet';
@@ -18,7 +18,11 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
20
  if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
22
26
  }) : (function(o, m, k, k2) {
23
27
  if (k2 === undefined) k2 = k;
24
28
  o[k2] = m[k];
@@ -28,4 +32,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
28
32
  };
29
33
  Object.defineProperty(exports, "__esModule", { value: true });
30
34
  __exportStar(require("./signer"), exports);
31
- __exportStar(require("./node-wallet"), exports);
@@ -1,6 +1,6 @@
1
- import { NodeProvider } from '../api';
1
+ import { NodeProvider, Number256, Token } from '../api';
2
2
  import { node } from '../api';
3
- import { Token } from '../api/api-alephium';
3
+ export declare type OutputRef = node.OutputRef;
4
4
  export interface SignResult {
5
5
  fromGroup: number;
6
6
  toGroup: number;
@@ -23,10 +23,10 @@ export declare type GetAccountsParams = undefined;
23
23
  export declare type GetAccountsResult = Account[];
24
24
  export interface SignTransferTxParams {
25
25
  signerAddress: string;
26
- destinations: node.Destination[];
27
- utxos?: node.OutputRef[];
26
+ destinations: Destination[];
27
+ utxos?: OutputRef[];
28
28
  gasAmount?: number;
29
- gasPrice?: string;
29
+ gasPrice?: Number256;
30
30
  submitTx?: boolean;
31
31
  }
32
32
  export interface SignTransferTxResult {
@@ -39,11 +39,11 @@ export interface SignTransferTxResult {
39
39
  export interface SignDeployContractTxParams {
40
40
  signerAddress: string;
41
41
  bytecode: string;
42
- initialAttoAlphAmount?: string;
42
+ initialAttoAlphAmount?: Number256;
43
43
  initialTokenAmounts?: Token[];
44
- issueTokenAmount?: string;
44
+ issueTokenAmount?: Number256;
45
45
  gasAmount?: number;
46
- gasPrice?: string;
46
+ gasPrice?: Number256;
47
47
  submitTx?: boolean;
48
48
  }
49
49
  export interface SignDeployContractTxResult {
@@ -59,7 +59,7 @@ export interface SignExecuteScriptTxParams {
59
59
  signerAddress: string;
60
60
  bytecode: string;
61
61
  attoAlphAmount?: string;
62
- tokens?: node.Token[];
62
+ tokens?: Token[];
63
63
  gasAmount?: number;
64
64
  gasPrice?: string;
65
65
  submitTx?: boolean;
@@ -111,9 +111,9 @@ export declare abstract class SignerWithNodeProvider implements SignerProvider {
111
111
  alwaysSubmitTx: boolean;
112
112
  abstract getAccounts(): Promise<Account[]>;
113
113
  getAccount(signerAddress: string): Promise<Account>;
114
- constructor(provider: NodeProvider, alwaysSubmitTx: boolean);
114
+ constructor(alwaysSubmitTx: boolean);
115
115
  private defaultSignerAddress;
116
- submitTransaction(unsignedTx: string, txHash: string, signerAddress?: string): Promise<SubmissionResult>;
116
+ submitTransaction(unsignedTx: string, signerAddress?: string): Promise<SubmissionResult>;
117
117
  private shouldSubmitTx;
118
118
  private usePublicKey;
119
119
  signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
@@ -141,3 +141,13 @@ export interface SubmissionResult {
141
141
  }
142
142
  export declare function verifyHexString(hexString: string, publicKey: string, signature: string): boolean;
143
143
  export declare function verifySignedMessage(message: string, publicKey: string, signature: string): boolean;
144
+ export interface Destination {
145
+ address: string;
146
+ attoAlphAmount: Number256;
147
+ tokens?: Token[];
148
+ lockTime?: number;
149
+ message?: string;
150
+ }
151
+ export declare function toApiDestination(data: Destination): node.Destination;
152
+ export declare function toApiDestinations(data: Destination[]): node.Destination[];
153
+ export declare function fromApiDestination(data: node.Destination): Destination;
@@ -18,7 +18,11 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
20
  if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
22
26
  }) : (function(o, m, k, k2) {
23
27
  if (k2 === undefined) k2 = k;
24
28
  o[k2] = m[k];
@@ -39,11 +43,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
43
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
44
  };
41
45
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.verifySignedMessage = exports.verifyHexString = exports.SignerWithNodeProvider = void 0;
46
+ exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.verifyHexString = exports.SignerWithNodeProvider = void 0;
43
47
  const elliptic_1 = require("elliptic");
48
+ const api_1 = require("../api");
44
49
  const utils = __importStar(require("../utils"));
45
50
  const utils_1 = require("../utils");
46
51
  const blakejs_1 = __importDefault(require("blakejs"));
52
+ const global_1 = require("../global");
47
53
  const ec = new elliptic_1.ec('secp256k1');
48
54
  (0, utils_1.assertType)();
49
55
  (0, utils_1.assertType)();
@@ -58,8 +64,8 @@ const ec = new elliptic_1.ec('secp256k1');
58
64
  (0, utils_1.assertType)();
59
65
  (0, utils_1.assertType)();
60
66
  class SignerWithNodeProvider {
61
- constructor(provider, alwaysSubmitTx) {
62
- this.provider = provider;
67
+ constructor(alwaysSubmitTx) {
68
+ this.provider = (0, global_1.getCurrentNodeProvider)();
63
69
  this.alwaysSubmitTx = alwaysSubmitTx;
64
70
  }
65
71
  async getAccount(signerAddress) {
@@ -75,9 +81,11 @@ class SignerWithNodeProvider {
75
81
  async defaultSignerAddress() {
76
82
  return (await this.getAccounts())[0].address;
77
83
  }
78
- async submitTransaction(unsignedTx, txHash, signerAddress) {
84
+ async submitTransaction(unsignedTx, signerAddress) {
85
+ const decoded = await this.provider.transactions.postTransactionsDecodeUnsignedTx({ unsignedTx: unsignedTx });
86
+ const txId = decoded.unsignedTx.txId;
79
87
  const address = typeof signerAddress !== 'undefined' ? signerAddress : await this.defaultSignerAddress();
80
- const signature = await this.signRaw(address, txHash);
88
+ const signature = await this.signRaw(address, txId);
81
89
  const params = { unsignedTx: unsignedTx, signature: signature };
82
90
  return this.provider.transactions.postTransactionsSubmit(params);
83
91
  }
@@ -100,7 +108,12 @@ class SignerWithNodeProvider {
100
108
  return this.handleSign({ signerAddress: params.signerAddress, ...response }, this.shouldSubmitTx(params));
101
109
  }
102
110
  async buildTransferTx(params) {
103
- return this.provider.transactions.postTransactionsBuild(await this.usePublicKey(params));
111
+ const data = {
112
+ ...(await this.usePublicKey(params)),
113
+ destinations: toApiDestinations(params.destinations),
114
+ gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
115
+ };
116
+ return this.provider.transactions.postTransactionsBuild(data);
104
117
  }
105
118
  async signDeployContractTx(params) {
106
119
  const response = await this.buildContractCreationTx(params);
@@ -109,14 +122,25 @@ class SignerWithNodeProvider {
109
122
  return { ...result, contractId: contractId, contractAddress: response.contractAddress };
110
123
  }
111
124
  async buildContractCreationTx(params) {
112
- return this.provider.contracts.postContractsUnsignedTxDeployContract(await this.usePublicKey(params));
125
+ const data = {
126
+ ...(await this.usePublicKey(params)),
127
+ initialAttoAlphAmount: (0, api_1.toApiNumber256Optional)(params.initialAttoAlphAmount),
128
+ initialTokenAmounts: (0, api_1.toApiTokens)(params.initialTokenAmounts),
129
+ issueTokenAmount: (0, api_1.toApiNumber256Optional)(params.issueTokenAmount),
130
+ gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
131
+ };
132
+ return this.provider.contracts.postContractsUnsignedTxDeployContract(data);
113
133
  }
114
134
  async signExecuteScriptTx(params) {
115
135
  const response = await this.buildScriptTx(params);
116
136
  return this.handleSign({ signerAddress: params.signerAddress, ...response }, this.shouldSubmitTx(params));
117
137
  }
118
138
  async buildScriptTx(params) {
119
- return this.provider.contracts.postContractsUnsignedTxExecuteScript(await this.usePublicKey(params));
139
+ const data = {
140
+ ...(await this.usePublicKey(params)),
141
+ tokens: (0, api_1.toApiTokens)(params.tokens)
142
+ };
143
+ return this.provider.contracts.postContractsUnsignedTxExecuteScript(data);
120
144
  }
121
145
  // in general, wallet should show the decoded information to user for confirmation
122
146
  // please overwrite this function for real wallet
@@ -182,3 +206,16 @@ function verifySignedMessage(message, publicKey, signature) {
182
206
  return verifyHexString(utils.binToHex(messageHash), publicKey, signature);
183
207
  }
184
208
  exports.verifySignedMessage = verifySignedMessage;
209
+ utils_1.assertType;
210
+ function toApiDestination(data) {
211
+ return { ...data, attoAlphAmount: (0, api_1.toApiNumber256)(data.attoAlphAmount), tokens: (0, api_1.toApiTokens)(data.tokens) };
212
+ }
213
+ exports.toApiDestination = toApiDestination;
214
+ function toApiDestinations(data) {
215
+ return data.map(toApiDestination);
216
+ }
217
+ exports.toApiDestinations = toApiDestinations;
218
+ function fromApiDestination(data) {
219
+ return { ...data, attoAlphAmount: (0, api_1.fromApiNumber256)(data.attoAlphAmount), tokens: (0, api_1.fromApiTokens)(data.tokens) };
220
+ }
221
+ exports.fromApiDestination = fromApiDestination;
@@ -1,2 +1 @@
1
- export * from './sign-verify';
2
1
  export * from './status';
@@ -18,7 +18,11 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
20
  if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
22
26
  }) : (function(o, m, k, k2) {
23
27
  if (k2 === undefined) k2 = k;
24
28
  o[k2] = m[k];
@@ -27,5 +31,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
31
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
32
  };
29
33
  Object.defineProperty(exports, "__esModule", { value: true });
30
- __exportStar(require("./sign-verify"), exports);
31
34
  __exportStar(require("./status"), exports);
@@ -1,5 +1,6 @@
1
- import { TxStatus } from '../api/api-alephium';
1
+ import { node } from '../api';
2
2
  import { Subscription, SubscribeOptions } from '../utils';
3
+ export declare type TxStatus = node.TxStatus;
3
4
  export declare class TxStatusSubscription extends Subscription<TxStatus> {
4
5
  readonly txId: string;
5
6
  readonly fromGroup?: number;
@@ -1,6 +1,5 @@
1
1
  export * from './address';
2
2
  export * from './bs58';
3
3
  export * from './djb2';
4
- export * from './password-crypto';
5
4
  export * from './utils';
6
5
  export * from './subscription';
@@ -18,7 +18,11 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
20
  if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
22
26
  }) : (function(o, m, k, k2) {
23
27
  if (k2 === undefined) k2 = k;
24
28
  o[k2] = m[k];
@@ -30,6 +34,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
34
  __exportStar(require("./address"), exports);
31
35
  __exportStar(require("./bs58"), exports);
32
36
  __exportStar(require("./djb2"), exports);
33
- __exportStar(require("./password-crypto"), exports);
34
37
  __exportStar(require("./utils"), exports);
35
38
  __exportStar(require("./subscription"), exports);
@@ -3,7 +3,6 @@ import { NodeProvider } from '../api';
3
3
  declare type MessageCallback<Message> = (message: Message) => Promise<void>;
4
4
  declare type ErrorCallback<Message> = (error: any, subscription: Subscription<Message>) => Promise<void>;
5
5
  export interface SubscribeOptions<Message> {
6
- provider: NodeProvider;
7
6
  pollingInterval: number;
8
7
  messageCallback: MessageCallback<Message>;
9
8
  errorCallback: ErrorCallback<Message>;
@@ -22,9 +22,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.Subscription = void 0;
24
24
  const eventemitter3_1 = __importDefault(require("eventemitter3"));
25
+ const global_1 = require("../global");
25
26
  class Subscription {
26
27
  constructor(options) {
27
- this.provider = options.provider;
28
+ this.provider = (0, global_1.getCurrentNodeProvider)();
28
29
  this.pollingInterval = options.pollingInterval;
29
30
  this.messageCallback = options.messageCallback;
30
31
  this.errorCallback = options.errorCallback;
@@ -7,9 +7,10 @@ export declare function convertHttpResponse<T>(response: node.HttpResponse<T, {
7
7
  detail: string;
8
8
  }>): T;
9
9
  export declare function signatureEncode(signature: EC.Signature): string;
10
- export declare const signatureDecode: (ec: EC, signature: string) => SignatureInput;
10
+ export declare function signatureDecode(ec: EC, signature: string): SignatureInput;
11
+ export declare function xorByte(intValue: number): number;
11
12
  export declare function isHexString(input: string): boolean;
12
- export declare const groupOfAddress: (address: string) => number;
13
+ export declare function groupOfAddress(address: string): number;
13
14
  export declare function contractIdFromAddress(address: string): Uint8Array;
14
15
  export declare function tokenIdFromAddress(address: string): Uint8Array;
15
16
  export declare function hexToBinUnsafe(hex: string): Uint8Array;
@@ -20,8 +21,8 @@ export declare function addressFromContractId(contractId: string): string;
20
21
  export declare function contractIdFromTx(txId: string, outputIndex: number): string;
21
22
  export declare function subContractId(parentContractId: string, pathInHex: string): string;
22
23
  export declare function stringToHex(str: string): string;
23
- export declare function hexToString(str: any): string;
24
- export declare function timeout(ms: number): Promise<unknown>;
24
+ export declare function hexToString(str: string): string;
25
+ export declare function timeout(ms: number): Promise<void>;
25
26
  declare type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
26
27
  export declare type Eq<X, Y> = _Eq<{
27
28
  [P in keyof X]: X[P];
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  return (mod && mod.__esModule) ? mod : { "default": mod };
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.assertType = exports.timeout = exports.hexToString = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.signatureDecode = exports.signatureEncode = exports.convertHttpResponse = void 0;
23
+ exports.assertType = exports.timeout = exports.hexToString = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.signatureEncode = exports.convertHttpResponse = void 0;
24
24
  const elliptic_1 = require("elliptic");
25
25
  const bn_js_1 = __importDefault(require("bn.js"));
26
26
  const blakejs_1 = __importDefault(require("blakejs"));
@@ -49,7 +49,7 @@ function signatureEncode(signature) {
49
49
  }
50
50
  exports.signatureEncode = signatureEncode;
51
51
  // the signature should be in hex string format for 64 bytes
52
- const signatureDecode = (ec, signature) => {
52
+ function signatureDecode(ec, signature) {
53
53
  if (signature.length !== 128) {
54
54
  throw new Error('Invalid signature length');
55
55
  }
@@ -62,15 +62,16 @@ const signatureDecode = (ec, signature) => {
62
62
  else {
63
63
  throw new Error('The signature is not normalized');
64
64
  }
65
- };
65
+ }
66
66
  exports.signatureDecode = signatureDecode;
67
- const xorByte = (intValue) => {
67
+ function xorByte(intValue) {
68
68
  const byte0 = (intValue >> 24) & 0xff;
69
69
  const byte1 = (intValue >> 16) & 0xff;
70
70
  const byte2 = (intValue >> 8) & 0xff;
71
71
  const byte3 = intValue & 0xff;
72
72
  return (byte0 ^ byte1 ^ byte2 ^ byte3) & 0xff;
73
- };
73
+ }
74
+ exports.xorByte = xorByte;
74
75
  function isHexString(input) {
75
76
  return input.length % 2 === 0 && /[0-9a-f]*$/.test(input);
76
77
  }
@@ -82,7 +83,7 @@ var AddressType;
82
83
  AddressType[AddressType["P2SH"] = 2] = "P2SH";
83
84
  AddressType[AddressType["P2C"] = 3] = "P2C";
84
85
  })(AddressType || (AddressType = {}));
85
- const groupOfAddress = (address) => {
86
+ function groupOfAddress(address) {
86
87
  const decoded = bs58_1.default.decode(address);
87
88
  if (decoded.length == 0)
88
89
  throw new Error('Address string is empty');
@@ -100,32 +101,32 @@ const groupOfAddress = (address) => {
100
101
  else {
101
102
  throw new Error(`Invalid asset address type: ${addressType}`);
102
103
  }
103
- };
104
+ }
104
105
  exports.groupOfAddress = groupOfAddress;
105
- const groupOfAddressBytes = (bytes) => {
106
+ function groupOfAddressBytes(bytes) {
106
107
  const hint = (0, djb2_1.default)(bytes) | 1;
107
108
  const hash = xorByte(hint);
108
109
  const group = hash % constants_1.TOTAL_NUMBER_OF_GROUPS;
109
110
  return group;
110
- };
111
+ }
111
112
  // Pay to public key hash address
112
- const groupOfP2pkhAddress = (address) => {
113
+ function groupOfP2pkhAddress(address) {
113
114
  if (address.length != 32) {
114
115
  throw new Error(`Invalid p2pkh address length: ${address.length}`);
115
116
  }
116
117
  return groupOfAddressBytes(address);
117
- };
118
+ }
118
119
  // Pay to multiple public key hash address
119
- const groupOfP2mpkhAddress = (address) => {
120
+ function groupOfP2mpkhAddress(address) {
120
121
  if ((address.length - 2) % 32 != 0) {
121
122
  throw new Error(`Invalid p2mpkh address length: ${address.length}`);
122
123
  }
123
124
  return groupOfAddressBytes(address.slice(1, 33));
124
- };
125
+ }
125
126
  // Pay to script hash address
126
- const groupOfP2shAddress = (address) => {
127
+ function groupOfP2shAddress(address) {
127
128
  return groupOfAddressBytes(address);
128
- };
129
+ }
129
130
  function contractIdFromAddress(address) {
130
131
  return idFromAddress(address);
131
132
  }
@@ -182,7 +183,7 @@ function contractIdFromTx(txId, outputIndex) {
182
183
  }
183
184
  exports.contractIdFromTx = contractIdFromTx;
184
185
  function subContractId(parentContractId, pathInHex) {
185
- const data = buffer_1.Buffer.concat([hexToBinUnsafe(pathInHex), hexToBinUnsafe(parentContractId)]);
186
+ const data = buffer_1.Buffer.concat([hexToBinUnsafe(parentContractId), hexToBinUnsafe(pathInHex)]);
186
187
  return binToHex(blakejs_1.default.blake2b(blakejs_1.default.blake2b(data, undefined, 32), undefined, 32));
187
188
  }
188
189
  exports.subContractId = subContractId;
@@ -195,7 +196,7 @@ function stringToHex(str) {
195
196
  }
196
197
  exports.stringToHex = stringToHex;
197
198
  function hexToString(str) {
198
- return buffer_1.Buffer.from(str.toString(), 'hex').toString();
199
+ return buffer_1.Buffer.from(str, 'hex').toString();
199
200
  }
200
201
  exports.hexToString = hexToString;
201
202
  function timeout(ms) {
@@ -0,0 +1,11 @@
1
+ {
2
+ "testPathIgnorePatterns": [".*/node_modules/"],
3
+ "transform": {
4
+ "^.+\\.(t|j)sx?$": "ts-jest"
5
+ },
6
+ "testMatch": ["**/*.test.ts"],
7
+ "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
8
+ "collectCoverage": true,
9
+ "coverageDirectory": "./coverage/",
10
+ "collectCoverageFrom": ["src/**/*.ts"]
11
+ }