@alephium/web3 0.5.0-rc.1 → 0.5.0-rc.10

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 (39) hide show
  1. package/dist/alephium-web3.min.js +1 -1
  2. package/dist/alephium-web3.min.js.LICENSE.txt +2 -0
  3. package/dist/alephium-web3.min.js.map +1 -1
  4. package/dist/src/api/api-alephium.d.ts +57 -20
  5. package/dist/src/api/api-alephium.js +57 -15
  6. package/dist/src/api/index.d.ts +1 -0
  7. package/dist/src/api/index.js +1 -0
  8. package/dist/src/api/types.d.ts +1 -1
  9. package/dist/src/api/types.js +6 -2
  10. package/dist/src/constants.d.ts +1 -0
  11. package/dist/src/constants.js +2 -1
  12. package/dist/src/contract/contract.d.ts +9 -4
  13. package/dist/src/contract/contract.js +31 -14
  14. package/dist/src/signer/signer.d.ts +29 -30
  15. package/dist/src/signer/signer.js +34 -25
  16. package/dist/src/signer/tx-builder.d.ts +2 -7
  17. package/dist/src/signer/tx-builder.js +10 -7
  18. package/dist/src/signer/types.d.ts +8 -0
  19. package/dist/src/transaction/sign-verify.d.ts +3 -2
  20. package/dist/src/transaction/sign-verify.js +4 -14
  21. package/dist/src/utils/index.d.ts +1 -0
  22. package/dist/src/utils/index.js +1 -0
  23. package/dist/src/utils/sign.d.ts +3 -0
  24. package/dist/src/utils/sign.js +89 -0
  25. package/dist/src/utils/utils.d.ts +4 -3
  26. package/dist/src/utils/utils.js +25 -10
  27. package/package.json +2 -1
  28. package/src/api/api-alephium.ts +88 -32
  29. package/src/api/index.ts +2 -0
  30. package/src/api/types.ts +12 -2
  31. package/src/constants.ts +1 -0
  32. package/src/contract/contract.ts +49 -20
  33. package/src/signer/signer.ts +69 -55
  34. package/src/signer/tx-builder.ts +13 -7
  35. package/src/signer/types.ts +10 -2
  36. package/src/transaction/sign-verify.ts +10 -15
  37. package/src/utils/index.ts +1 -0
  38. package/src/utils/sign.ts +66 -0
  39. package/src/utils/utils.ts +26 -10
@@ -2,13 +2,8 @@ import { NodeProvider } from '../api';
2
2
  import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult } from './types';
3
3
  export declare abstract class TransactionBuilder {
4
4
  abstract get nodeProvider(): NodeProvider;
5
- static create(baseUrl: string, apiKey?: string): {
6
- readonly nodeProvider: NodeProvider;
7
- buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<Omit<SignTransferTxResult, "signature">>;
8
- buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<Omit<SignDeployContractTxResult, "signature">>;
9
- buildExecuteScriptTx(params: SignExecuteScriptTxParams, publicKey: string): Promise<Omit<SignExecuteScriptTxResult, "signature">>;
10
- buildUnsignedTx(params: SignUnsignedTxParams): Promise<Omit<SignUnsignedTxResult, "signature">>;
11
- };
5
+ static from(nodeProvider: NodeProvider): TransactionBuilder;
6
+ static from(baseUrl: string, apiKey?: string): TransactionBuilder;
12
7
  private static validatePublicKey;
13
8
  buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<Omit<SignTransferTxResult, 'signature'>>;
14
9
  buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<Omit<SignDeployContractTxResult, 'signature'>>;
@@ -23,25 +23,26 @@ const api_1 = require("../api");
23
23
  const utils_1 = require("../utils");
24
24
  const signer_1 = require("./signer");
25
25
  class TransactionBuilder {
26
- static create(baseUrl, apiKey) {
27
- const nodeProvider = new api_1.NodeProvider(baseUrl, apiKey);
26
+ static from(param0, param1) {
27
+ const nodeProvider = typeof param0 === 'string' ? new api_1.NodeProvider(param0, param1) : param0;
28
28
  return new (class extends TransactionBuilder {
29
29
  get nodeProvider() {
30
30
  return nodeProvider;
31
31
  }
32
32
  })();
33
33
  }
34
- static validatePublicKey(params, publicKey) {
35
- const address = (0, utils_1.addressFromPublicKey)(publicKey);
34
+ static validatePublicKey(params, publicKey, keyType) {
35
+ const address = (0, utils_1.addressFromPublicKey)(publicKey, keyType);
36
36
  if (address !== params.signerAddress) {
37
37
  throw new Error('Unmatched public key');
38
38
  }
39
39
  }
40
40
  async buildTransferTx(params, publicKey) {
41
- TransactionBuilder.validatePublicKey(params, publicKey);
41
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType ?? 'default');
42
42
  const { destinations, gasPrice, ...rest } = params;
43
43
  const data = {
44
44
  fromPublicKey: publicKey,
45
+ fromPublicKeyType: params.signerKeyType,
45
46
  destinations: (0, signer_1.toApiDestinations)(destinations),
46
47
  gasPrice: (0, api_1.toApiNumber256Optional)(gasPrice),
47
48
  ...rest
@@ -50,10 +51,11 @@ class TransactionBuilder {
50
51
  return { ...response, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
51
52
  }
52
53
  async buildDeployContractTx(params, publicKey) {
53
- TransactionBuilder.validatePublicKey(params, publicKey);
54
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType ?? 'default');
54
55
  const { initialAttoAlphAmount, initialTokenAmounts, issueTokenAmount, gasPrice, ...rest } = params;
55
56
  const data = {
56
57
  fromPublicKey: publicKey,
58
+ fromPublicKeyType: params.signerKeyType,
57
59
  initialAttoAlphAmount: (0, api_1.toApiNumber256Optional)(initialAttoAlphAmount),
58
60
  initialTokenAmounts: (0, api_1.toApiTokens)(initialTokenAmounts),
59
61
  issueTokenAmount: (0, api_1.toApiNumber256Optional)(issueTokenAmount),
@@ -65,10 +67,11 @@ class TransactionBuilder {
65
67
  return { ...response, groupIndex: response.fromGroup, contractId, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
66
68
  }
67
69
  async buildExecuteScriptTx(params, publicKey) {
68
- TransactionBuilder.validatePublicKey(params, publicKey);
70
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType ?? 'default');
69
71
  const { attoAlphAmount, tokens, gasPrice, ...rest } = params;
70
72
  const data = {
71
73
  fromPublicKey: publicKey,
74
+ fromPublicKeyType: params.signerKeyType,
72
75
  attoAlphAmount: (0, api_1.toApiNumber256Optional)(attoAlphAmount),
73
76
  tokens: (0, api_1.toApiTokens)(tokens),
74
77
  gasPrice: (0, api_1.toApiNumber256Optional)(gasPrice),
@@ -9,16 +9,20 @@ export interface Destination {
9
9
  lockTime?: number;
10
10
  message?: string;
11
11
  }
12
+ export declare type KeyType = 'default' | 'bip340-schnorr';
12
13
  export interface Account {
14
+ keyType: KeyType;
13
15
  address: string;
14
16
  group: number;
15
17
  publicKey: string;
16
18
  }
17
19
  export declare type SignerAddress = {
18
20
  signerAddress: string;
21
+ signerKeyType?: KeyType;
19
22
  };
20
23
  export interface SignTransferTxParams {
21
24
  signerAddress: string;
25
+ signerKeyType?: KeyType;
22
26
  destinations: Destination[];
23
27
  utxos?: OutputRef[];
24
28
  gasAmount?: number;
@@ -35,6 +39,7 @@ export interface SignTransferTxResult {
35
39
  }
36
40
  export interface SignDeployContractTxParams {
37
41
  signerAddress: string;
42
+ signerKeyType?: KeyType;
38
43
  bytecode: string;
39
44
  initialAttoAlphAmount?: Number256;
40
45
  initialTokenAmounts?: Token[];
@@ -54,6 +59,7 @@ export interface SignDeployContractTxResult {
54
59
  }
55
60
  export interface SignExecuteScriptTxParams {
56
61
  signerAddress: string;
62
+ signerKeyType?: KeyType;
57
63
  bytecode: string;
58
64
  attoAlphAmount?: Number256;
59
65
  tokens?: Token[];
@@ -70,6 +76,7 @@ export interface SignExecuteScriptTxResult {
70
76
  }
71
77
  export interface SignUnsignedTxParams {
72
78
  signerAddress: string;
79
+ signerKeyType?: KeyType;
73
80
  unsignedTx: string;
74
81
  }
75
82
  export interface SignUnsignedTxResult {
@@ -83,6 +90,7 @@ export interface SignUnsignedTxResult {
83
90
  }
84
91
  export interface SignMessageParams {
85
92
  signerAddress: string;
93
+ signerKeyType?: KeyType;
86
94
  message: string;
87
95
  }
88
96
  export interface SignMessageResult {
@@ -1,2 +1,3 @@
1
- export declare function transactionSign(txHash: string, privateKey: string): string;
2
- export declare function transactionVerifySignature(txHash: string, publicKey: string, signature: string): boolean;
1
+ import { KeyType } from '../signer';
2
+ export declare function transactionSign(txId: string, privateKey: string, keyType: KeyType): string;
3
+ export declare function transactionVerifySignature(txId: string, publicKey: string, signature: string, keyType: KeyType): boolean;
@@ -42,21 +42,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
43
  exports.transactionVerifySignature = exports.transactionSign = void 0;
44
44
  const utils = __importStar(require("../utils"));
45
- const elliptic_1 = require("elliptic");
46
- const ec = new elliptic_1.ec('secp256k1');
47
- function transactionSign(txHash, privateKey) {
48
- const keyPair = ec.keyFromPrivate(privateKey);
49
- const signature = keyPair.sign(txHash);
50
- return utils.encodeSignature(signature);
45
+ function transactionSign(txId, privateKey, keyType) {
46
+ return utils.sign(txId, privateKey, keyType);
51
47
  }
52
48
  exports.transactionSign = transactionSign;
53
- function transactionVerifySignature(txHash, publicKey, signature) {
54
- try {
55
- const key = ec.keyFromPublic(publicKey, 'hex');
56
- return key.verify(txHash, utils.signatureDecode(ec, signature));
57
- }
58
- catch (error) {
59
- return false;
60
- }
49
+ function transactionVerifySignature(txId, publicKey, signature, keyType) {
50
+ return utils.verifySignature(txId, publicKey, signature, keyType);
61
51
  }
62
52
  exports.transactionVerifySignature = transactionVerifySignature;
@@ -3,3 +3,4 @@ export * from './bs58';
3
3
  export * from './djb2';
4
4
  export * from './utils';
5
5
  export * from './subscription';
6
+ export * from './sign';
@@ -36,3 +36,4 @@ __exportStar(require("./bs58"), exports);
36
36
  __exportStar(require("./djb2"), exports);
37
37
  __exportStar(require("./utils"), exports);
38
38
  __exportStar(require("./subscription"), exports);
39
+ __exportStar(require("./sign"), exports);
@@ -0,0 +1,3 @@
1
+ import { KeyType } from '../signer';
2
+ export declare function sign(hash: string, privateKey: string, _keyType: KeyType): string;
3
+ export declare function verifySignature(hash: string, publicKey: string, signature: string, _keyType: KeyType): boolean;
@@ -0,0 +1,89 @@
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
+ 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);
26
+ }) : (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ o[k2] = m[k];
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
+ });
35
+ var __importStar = (this && this.__importStar) || function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.verifySignature = exports.sign = void 0;
44
+ const elliptic_1 = require("elliptic");
45
+ const __1 = require("..");
46
+ const necc = __importStar(require("@noble/secp256k1"));
47
+ const crypto_1 = require("crypto");
48
+ const ec = new elliptic_1.ec('secp256k1');
49
+ necc.utils.sha256Sync = (...messages) => {
50
+ const sha256 = (0, crypto_1.createHash)('sha256');
51
+ for (const message of messages)
52
+ sha256.update(message);
53
+ return sha256.digest();
54
+ };
55
+ necc.utils.hmacSha256Sync = (key, ...messages) => {
56
+ const hash = (0, crypto_1.createHmac)('sha256', Buffer.from(key));
57
+ messages.forEach((m) => hash.update(m));
58
+ return Uint8Array.from(hash.digest());
59
+ };
60
+ // hash has to be 32 bytes
61
+ function sign(hash, privateKey, _keyType) {
62
+ const keyType = _keyType ?? 'default';
63
+ if (keyType === 'default') {
64
+ const key = ec.keyFromPrivate(privateKey);
65
+ const signature = key.sign(hash);
66
+ return (0, __1.encodeSignature)(signature);
67
+ }
68
+ else {
69
+ const signature = necc.schnorr.signSync((0, __1.hexToBinUnsafe)(hash), (0, __1.hexToBinUnsafe)(privateKey));
70
+ return (0, __1.binToHex)(signature);
71
+ }
72
+ }
73
+ exports.sign = sign;
74
+ function verifySignature(hash, publicKey, signature, _keyType) {
75
+ const keyType = _keyType ?? 'default';
76
+ try {
77
+ if (keyType === 'default') {
78
+ const key = ec.keyFromPublic(publicKey, 'hex');
79
+ return key.verify(hash, (0, __1.signatureDecode)(ec, signature));
80
+ }
81
+ else {
82
+ return necc.schnorr.verifySync((0, __1.hexToBinUnsafe)(signature), (0, __1.hexToBinUnsafe)(hash), (0, __1.hexToBinUnsafe)(publicKey));
83
+ }
84
+ }
85
+ catch (error) {
86
+ return false;
87
+ }
88
+ }
89
+ exports.verifySignature = verifySignature;
@@ -1,5 +1,6 @@
1
1
  import { ec as EC, SignatureInput } from 'elliptic';
2
2
  import BN from 'bn.js';
3
+ import { KeyType } from '../signer';
3
4
  export declare function encodeSignature(signature: EC.Signature | {
4
5
  r: BN;
5
6
  s: BN;
@@ -13,9 +14,9 @@ export declare function contractIdFromAddress(address: string): Uint8Array;
13
14
  export declare function tokenIdFromAddress(address: string): Uint8Array;
14
15
  export declare function hexToBinUnsafe(hex: string): Uint8Array;
15
16
  export declare function binToHex(bin: Uint8Array): string;
16
- export declare function groupOfPrivateKey(privateKey: string): number;
17
- export declare function publicKeyFromPrivateKey(privateKey: string): string;
18
- export declare function addressFromPublicKey(publicKey: string): string;
17
+ export declare function groupOfPrivateKey(privateKey: string, keyType: KeyType): number;
18
+ export declare function publicKeyFromPrivateKey(privateKey: string, _keyType: KeyType): string;
19
+ export declare function addressFromPublicKey(publicKey: string, _keyType: KeyType): string;
19
20
  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, group: number): string;
@@ -153,20 +153,35 @@ function binToHex(bin) {
153
153
  return buffer_1.Buffer.from(bin).toString('hex');
154
154
  }
155
155
  exports.binToHex = binToHex;
156
- function groupOfPrivateKey(privateKey) {
157
- return groupOfAddress(addressFromPublicKey(publicKeyFromPrivateKey(privateKey)));
156
+ function groupOfPrivateKey(privateKey, keyType) {
157
+ return groupOfAddress(addressFromPublicKey(publicKeyFromPrivateKey(privateKey, keyType), keyType));
158
158
  }
159
159
  exports.groupOfPrivateKey = groupOfPrivateKey;
160
- function publicKeyFromPrivateKey(privateKey) {
161
- const key = ec.keyFromPrivate(privateKey);
162
- return key.getPublic(true, 'hex');
160
+ function publicKeyFromPrivateKey(privateKey, _keyType) {
161
+ const keyType = _keyType ?? 'default';
162
+ if (keyType === 'default') {
163
+ const key = ec.keyFromPrivate(privateKey);
164
+ return key.getPublic(true, 'hex');
165
+ }
166
+ else {
167
+ return ec.g.mul(new bn_js_1.default(privateKey, 16)).encode('hex', true).slice(2);
168
+ }
163
169
  }
164
170
  exports.publicKeyFromPrivateKey = publicKeyFromPrivateKey;
165
- function addressFromPublicKey(publicKey) {
166
- const addressType = buffer_1.Buffer.from([AddressType.P2PKH]);
167
- const hash = buffer_1.Buffer.from(blakejs_1.default.blake2b(buffer_1.Buffer.from(publicKey, 'hex'), undefined, 32));
168
- const bytes = buffer_1.Buffer.concat([addressType, hash]);
169
- return bs58_1.default.encode(bytes);
171
+ function addressFromPublicKey(publicKey, _keyType) {
172
+ const keyType = _keyType ?? 'default';
173
+ if (keyType === 'default') {
174
+ const addressType = buffer_1.Buffer.from([AddressType.P2PKH]);
175
+ const hash = buffer_1.Buffer.from(blakejs_1.default.blake2b(buffer_1.Buffer.from(publicKey, 'hex'), undefined, 32));
176
+ const bytes = buffer_1.Buffer.concat([addressType, hash]);
177
+ return bs58_1.default.encode(bytes);
178
+ }
179
+ else {
180
+ const lockupScript = buffer_1.Buffer.from(`0101000000000458144020${publicKey}8685`, 'hex');
181
+ const lockupScriptHash = blakejs_1.default.blake2b(lockupScript, undefined, 32);
182
+ const addressType = buffer_1.Buffer.from([AddressType.P2SH]);
183
+ return bs58_1.default.encode(buffer_1.Buffer.concat([addressType, lockupScriptHash]));
184
+ }
170
185
  }
171
186
  exports.addressFromPublicKey = addressFromPublicKey;
172
187
  function addressFromContractId(contractId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.5.0-rc.1",
3
+ "version": "0.5.0-rc.10",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -40,6 +40,7 @@
40
40
  },
41
41
  "type": "commonjs",
42
42
  "dependencies": {
43
+ "@noble/secp256k1": "1.7.1",
43
44
  "base-x": "4.0.0",
44
45
  "blakejs": "1.2.1",
45
46
  "buffer": "^6.0.3",
@@ -202,9 +202,12 @@ export interface BrokerInfo {
202
202
  }
203
203
 
204
204
  export interface BuildDeployContractTx {
205
- /** @format public-key */
205
+ /** @format hex-string */
206
206
  fromPublicKey: string
207
207
 
208
+ /** @format hex-string */
209
+ fromPublicKeyType?: string
210
+
208
211
  /** @format hex-string */
209
212
  bytecode: string
210
213
 
@@ -247,9 +250,12 @@ export interface BuildDeployContractTxResult {
247
250
  }
248
251
 
249
252
  export interface BuildExecuteScriptTx {
250
- /** @format public-key */
253
+ /** @format hex-string */
251
254
  fromPublicKey: string
252
255
 
256
+ /** @format hex-string */
257
+ fromPublicKeyType?: string
258
+
253
259
  /** @format hex-string */
254
260
  bytecode: string
255
261
 
@@ -346,8 +352,11 @@ export interface BuildSweepAddressTransactionsResult {
346
352
  }
347
353
 
348
354
  export interface BuildTransaction {
349
- /** @format public-key */
355
+ /** @format hex-string */
350
356
  fromPublicKey: string
357
+
358
+ /** @format hex-string */
359
+ fromPublicKeyType?: string
351
360
  destinations: Destination[]
352
361
  utxos?: OutputRef[]
353
362
 
@@ -695,6 +704,15 @@ export interface MemPooled {
695
704
  type: string
696
705
  }
697
706
 
707
+ export interface MempoolTransactions {
708
+ /** @format int32 */
709
+ fromGroup: number
710
+
711
+ /** @format int32 */
712
+ toGroup: number
713
+ transactions: TransactionTemplate[]
714
+ }
715
+
698
716
  export interface MinerAddresses {
699
717
  addresses: string[]
700
718
  }
@@ -1004,15 +1022,6 @@ export interface Unban {
1004
1022
  type: string
1005
1023
  }
1006
1024
 
1007
- export interface UnconfirmedTransactions {
1008
- /** @format int32 */
1009
- fromGroup: number
1010
-
1011
- /** @format int32 */
1012
- toGroup: number
1013
- unconfirmedTransactions: TransactionTemplate[]
1014
- }
1015
-
1016
1025
  export interface Unreachable {
1017
1026
  peers: string[]
1018
1027
  type: string
@@ -1334,7 +1343,7 @@ export class HttpClient<SecurityDataType = unknown> {
1334
1343
 
1335
1344
  /**
1336
1345
  * @title Alephium API
1337
- * @version 1.7.0
1346
+ * @version 1.7.1
1338
1347
  * @baseUrl ../
1339
1348
  */
1340
1349
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -2070,25 +2079,6 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2070
2079
  }).then(convertHttpResponse)
2071
2080
  }
2072
2081
  transactions = {
2073
- /**
2074
- * No description
2075
- *
2076
- * @tags Transactions
2077
- * @name GetTransactionsUnconfirmed
2078
- * @summary List unconfirmed transactions
2079
- * @request GET:/transactions/unconfirmed
2080
- */
2081
- getTransactionsUnconfirmed: (params: RequestParams = {}) =>
2082
- this.request<
2083
- UnconfirmedTransactions[],
2084
- BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
2085
- >({
2086
- path: `/transactions/unconfirmed`,
2087
- method: 'GET',
2088
- format: 'json',
2089
- ...params
2090
- }).then(convertHttpResponse),
2091
-
2092
2082
  /**
2093
2083
  * No description
2094
2084
  *
@@ -2211,6 +2201,72 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2211
2201
  ...params
2212
2202
  }).then(convertHttpResponse)
2213
2203
  }
2204
+ mempool = {
2205
+ /**
2206
+ * No description
2207
+ *
2208
+ * @tags Mempool
2209
+ * @name GetMempoolTransactions
2210
+ * @summary List mempool transactions
2211
+ * @request GET:/mempool/transactions
2212
+ */
2213
+ getMempoolTransactions: (params: RequestParams = {}) =>
2214
+ this.request<
2215
+ MempoolTransactions[],
2216
+ BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
2217
+ >({
2218
+ path: `/mempool/transactions`,
2219
+ method: 'GET',
2220
+ format: 'json',
2221
+ ...params
2222
+ }).then(convertHttpResponse),
2223
+
2224
+ /**
2225
+ * No description
2226
+ *
2227
+ * @tags Mempool
2228
+ * @name DeleteMempoolTransactions
2229
+ * @summary Remove all transactions from mempool
2230
+ * @request DELETE:/mempool/transactions
2231
+ */
2232
+ deleteMempoolTransactions: (params: RequestParams = {}) =>
2233
+ this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2234
+ path: `/mempool/transactions`,
2235
+ method: 'DELETE',
2236
+ ...params
2237
+ }).then(convertHttpResponse),
2238
+
2239
+ /**
2240
+ * No description
2241
+ *
2242
+ * @tags Mempool
2243
+ * @name PutMempoolTransactionsRebroadcast
2244
+ * @summary Rebroadcase a mempool transaction to the network
2245
+ * @request PUT:/mempool/transactions/rebroadcast
2246
+ */
2247
+ putMempoolTransactionsRebroadcast: (query: { txId: string }, params: RequestParams = {}) =>
2248
+ this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2249
+ path: `/mempool/transactions/rebroadcast`,
2250
+ method: 'PUT',
2251
+ query: query,
2252
+ ...params
2253
+ }).then(convertHttpResponse),
2254
+
2255
+ /**
2256
+ * No description
2257
+ *
2258
+ * @tags Mempool
2259
+ * @name PutMempoolTransactionsValidate
2260
+ * @summary Validate all mempool transactions and remove invalid ones
2261
+ * @request PUT:/mempool/transactions/validate
2262
+ */
2263
+ putMempoolTransactionsValidate: (params: RequestParams = {}) =>
2264
+ this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2265
+ path: `/mempool/transactions/validate`,
2266
+ method: 'PUT',
2267
+ ...params
2268
+ }).then(convertHttpResponse)
2269
+ }
2214
2270
  contracts = {
2215
2271
  /**
2216
2272
  * No description
package/src/api/index.ts CHANGED
@@ -58,6 +58,7 @@ export class NodeProvider {
58
58
  readonly blockflow: NodeApi<string>['blockflow']
59
59
  readonly addresses: NodeApi<string>['addresses']
60
60
  readonly transactions: NodeApi<string>['transactions']
61
+ readonly mempool: NodeApi<string>['mempool']
61
62
  readonly contracts: NodeApi<string>['contracts']
62
63
  readonly multisig: NodeApi<string>['multisig']
63
64
  readonly utils: NodeApi<string>['utils']
@@ -83,6 +84,7 @@ export class NodeProvider {
83
84
  this.blockflow = { ...nodeApi.blockflow }
84
85
  this.addresses = { ...nodeApi.addresses }
85
86
  this.transactions = { ...nodeApi.transactions }
87
+ this.mempool = { ...nodeApi.mempool }
86
88
  this.contracts = { ...nodeApi.contracts }
87
89
  this.multisig = { ...nodeApi.multisig }
88
90
  this.utils = { ...nodeApi.utils }
package/src/api/types.ts CHANGED
@@ -162,7 +162,13 @@ function _fromApiVal(vals: node.Val[], valIndex: number, tpe: string): [result:
162
162
  }
163
163
  }
164
164
 
165
- export function fromApiVals(vals: node.Val[], names: string[], types: string[]): NamedVals {
165
+ export function fromApiVals(
166
+ vals: node.Val[],
167
+ names: string[],
168
+ types: string[],
169
+ optionalNames: string[] = [],
170
+ optionalTypes: string[] = []
171
+ ): NamedVals {
166
172
  let valIndex = 0
167
173
  const result: NamedVals = {}
168
174
  types.forEach((currentType, index) => {
@@ -171,7 +177,11 @@ export function fromApiVals(vals: node.Val[], names: string[], types: string[]):
171
177
  valIndex = nextIndex
172
178
  result[`${currentName}`] = val
173
179
  })
174
- return result
180
+ if (valIndex === vals.length) {
181
+ return result
182
+ }
183
+ const optionalFields = fromApiVals(vals.slice(valIndex), optionalNames, optionalTypes)
184
+ return { ...result, ...optionalFields }
175
185
  }
176
186
 
177
187
  export function fromApiArray(vals: node.Val[], types: string[]): Val[] {
package/src/constants.ts CHANGED
@@ -20,3 +20,4 @@ export const TOTAL_NUMBER_OF_GROUPS = 4
20
20
  export const MIN_UTXO_SET_AMOUNT = BigInt(1000000000000)
21
21
  export const ALPH_TOKEN_ID = ''.padStart(64, '0')
22
22
  export const ONE_ALPH = 10n ** 18n
23
+ export const DUST_AMOUNT = 10n ** 15n