@alephium/web3 1.11.7 → 1.12.0-danube.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/address/address.d.ts +12 -1
- package/dist/src/address/address.js +119 -11
- package/dist/src/api/api-alephium.d.ts +84 -50
- package/dist/src/api/types.d.ts +1 -1
- package/dist/src/api/types.js +10 -5
- package/dist/src/codec/lockup-script-codec.d.ts +11 -2
- package/dist/src/codec/lockup-script-codec.js +8 -1
- package/dist/src/codec/unlock-script-codec.d.ts +11 -3
- package/dist/src/codec/unlock-script-codec.js +14 -4
- package/dist/src/contract/contract.d.ts +14 -9
- package/dist/src/contract/contract.js +42 -21
- package/dist/src/contract/deployment.d.ts +2 -0
- package/dist/src/contract/ralph.js +2 -1
- package/dist/src/signer/signer.d.ts +13 -13
- package/dist/src/signer/signer.js +84 -9
- package/dist/src/signer/tx-builder.d.ts +4 -4
- package/dist/src/signer/tx-builder.js +41 -0
- package/dist/src/signer/types.d.ts +14 -1
- package/dist/src/utils/sign.js +2 -2
- package/dist/src/utils/webcrypto.d.ts +3 -1
- package/package.json +1 -1
- package/src/address/address.ts +120 -12
- package/src/api/api-alephium.ts +87 -47
- package/src/api/types.ts +10 -5
- package/src/codec/lockup-script-codec.ts +19 -2
- package/src/codec/unlock-script-codec.ts +23 -8
- package/src/contract/contract.ts +72 -33
- package/src/contract/deployment.ts +2 -0
- package/src/contract/ralph.ts +5 -2
- package/src/signer/signer.ts +118 -24
- package/src/signer/tx-builder.ts +61 -13
- package/src/signer/types.ts +31 -6
- package/src/utils/sign.ts +2 -2
|
@@ -4,11 +4,17 @@ export declare enum AddressType {
|
|
|
4
4
|
P2PKH = 0,
|
|
5
5
|
P2MPKH = 1,
|
|
6
6
|
P2SH = 2,
|
|
7
|
-
P2C = 3
|
|
7
|
+
P2C = 3,
|
|
8
|
+
P2PK = 4
|
|
8
9
|
}
|
|
9
10
|
export declare function validateAddress(address: string): void;
|
|
10
11
|
export declare function isValidAddress(address: string): boolean;
|
|
12
|
+
export declare function addressToBytes(address: string): Uint8Array;
|
|
11
13
|
export declare function isAssetAddress(address: string): boolean;
|
|
14
|
+
export declare function isGrouplessAddress(address: string): boolean;
|
|
15
|
+
export declare function isGrouplessAddressWithoutGroupIndex(address: string): boolean;
|
|
16
|
+
export declare function isGrouplessAddressWithGroupIndex(address: string): boolean;
|
|
17
|
+
export declare function defaultGroupOfGrouplessAddress(pubKey: Uint8Array): number;
|
|
12
18
|
export declare function isContractAddress(address: string): boolean;
|
|
13
19
|
export declare function groupOfAddress(address: string): number;
|
|
14
20
|
export declare function contractIdFromAddress(address: string): Uint8Array;
|
|
@@ -22,3 +28,8 @@ export declare function addressFromTokenId(tokenId: string): string;
|
|
|
22
28
|
export declare function contractIdFromTx(txId: string, outputIndex: number): string;
|
|
23
29
|
export declare function subContractId(parentContractId: string, pathInHex: string, group: number): string;
|
|
24
30
|
export declare function groupOfLockupScript(lockupScript: LockupScript): number;
|
|
31
|
+
export declare function groupFromBytes(bytes: Uint8Array): number;
|
|
32
|
+
export declare function groupFromHint(hint: number): number;
|
|
33
|
+
export declare function hasExplicitGroupIndex(address: string): boolean;
|
|
34
|
+
export declare function addressWithoutExplicitGroupIndex(address: string): string;
|
|
35
|
+
export declare function addressFromLockupScript(lockupScript: LockupScript): string;
|
|
@@ -43,7 +43,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
43
43
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.groupOfLockupScript = exports.subContractId = exports.contractIdFromTx = exports.addressFromTokenId = exports.addressFromContractId = exports.addressFromScript = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.groupOfPrivateKey = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isContractAddress = exports.isAssetAddress = exports.isValidAddress = exports.validateAddress = exports.AddressType = void 0;
|
|
46
|
+
exports.addressFromLockupScript = exports.addressWithoutExplicitGroupIndex = exports.hasExplicitGroupIndex = exports.groupFromHint = exports.groupFromBytes = exports.groupOfLockupScript = exports.subContractId = exports.contractIdFromTx = exports.addressFromTokenId = exports.addressFromContractId = exports.addressFromScript = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.groupOfPrivateKey = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isContractAddress = exports.defaultGroupOfGrouplessAddress = exports.isGrouplessAddressWithGroupIndex = exports.isGrouplessAddressWithoutGroupIndex = exports.isGrouplessAddress = exports.isAssetAddress = exports.addressToBytes = exports.isValidAddress = exports.validateAddress = exports.AddressType = void 0;
|
|
47
47
|
const elliptic_1 = require("elliptic");
|
|
48
48
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
49
49
|
const constants_1 = require("../constants");
|
|
@@ -54,6 +54,7 @@ const lockup_script_codec_1 = require("../codec/lockup-script-codec");
|
|
|
54
54
|
const codec_1 = require("../codec");
|
|
55
55
|
const djb2_1 = __importDefault(require("../utils/djb2"));
|
|
56
56
|
const error_1 = require("../error");
|
|
57
|
+
const codec_2 = require("../codec/codec");
|
|
57
58
|
const ec = new elliptic_1.ec('secp256k1');
|
|
58
59
|
const PublicKeyHashSize = 32;
|
|
59
60
|
var AddressType;
|
|
@@ -62,6 +63,7 @@ var AddressType;
|
|
|
62
63
|
AddressType[AddressType["P2MPKH"] = 1] = "P2MPKH";
|
|
63
64
|
AddressType[AddressType["P2SH"] = 2] = "P2SH";
|
|
64
65
|
AddressType[AddressType["P2C"] = 3] = "P2C";
|
|
66
|
+
AddressType[AddressType["P2PK"] = 4] = "P2PK";
|
|
65
67
|
})(AddressType = exports.AddressType || (exports.AddressType = {}));
|
|
66
68
|
function validateAddress(address) {
|
|
67
69
|
decodeAndValidateAddress(address);
|
|
@@ -78,7 +80,7 @@ function isValidAddress(address) {
|
|
|
78
80
|
}
|
|
79
81
|
exports.isValidAddress = isValidAddress;
|
|
80
82
|
function decodeAndValidateAddress(address) {
|
|
81
|
-
const decoded = (
|
|
83
|
+
const decoded = addressToBytes(address);
|
|
82
84
|
if (decoded.length === 0)
|
|
83
85
|
throw new Error('Address is empty');
|
|
84
86
|
const addressType = decoded[0];
|
|
@@ -106,13 +108,68 @@ function decodeAndValidateAddress(address) {
|
|
|
106
108
|
if (decoded.length === 33)
|
|
107
109
|
return decoded;
|
|
108
110
|
}
|
|
111
|
+
else if (addressType === AddressType.P2PK) {
|
|
112
|
+
if (decoded.length === 40) {
|
|
113
|
+
// [type, keyType, ...publicKey, ...checkSum, ...groupByte]
|
|
114
|
+
const publicKeyLikeBytes = decoded.slice(1, 35);
|
|
115
|
+
const checksum = (0, utils_1.binToHex)(decoded.slice(35, 39));
|
|
116
|
+
const expectedChecksum = (0, utils_1.binToHex)(codec_1.intAs4BytesCodec.encode((0, djb2_1.default)(publicKeyLikeBytes)));
|
|
117
|
+
if (checksum !== expectedChecksum) {
|
|
118
|
+
throw new Error(`Invalid checksum for P2PK address: ${address}`);
|
|
119
|
+
}
|
|
120
|
+
const group = codec_2.byteCodec.decode(decoded.slice(39, 40));
|
|
121
|
+
validateGroupIndex(group);
|
|
122
|
+
return decoded;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
109
125
|
throw new Error(`Invalid address: ${address}`);
|
|
110
126
|
}
|
|
127
|
+
function addressToBytes(address) {
|
|
128
|
+
if (hasExplicitGroupIndex(address)) {
|
|
129
|
+
const groupIndex = parseGroupIndex(address[address.length - 1]);
|
|
130
|
+
const decoded = (0, bs58_1.base58ToBytes)(address.slice(0, address.length - 2));
|
|
131
|
+
if (decoded[0] === 0x04 && decoded.length === 39) {
|
|
132
|
+
const groupByte = codec_2.byteCodec.encode(groupIndex);
|
|
133
|
+
return new Uint8Array([...decoded, ...groupByte]);
|
|
134
|
+
}
|
|
135
|
+
throw new Error(`Invalid groupless address: ${address}`);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const decoded = (0, bs58_1.base58ToBytes)(address);
|
|
139
|
+
if (decoded[0] === 0x04 && decoded.length === 39) {
|
|
140
|
+
const group = defaultGroupOfGrouplessAddress(decoded.slice(2, 35));
|
|
141
|
+
const groupByte = codec_2.byteCodec.encode(group);
|
|
142
|
+
return new Uint8Array([...decoded, ...groupByte]);
|
|
143
|
+
}
|
|
144
|
+
return decoded;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.addressToBytes = addressToBytes;
|
|
111
148
|
function isAssetAddress(address) {
|
|
112
149
|
const addressType = decodeAndValidateAddress(address)[0];
|
|
113
|
-
return addressType === AddressType.P2PKH ||
|
|
150
|
+
return (addressType === AddressType.P2PKH ||
|
|
151
|
+
addressType === AddressType.P2MPKH ||
|
|
152
|
+
addressType === AddressType.P2SH ||
|
|
153
|
+
addressType === AddressType.P2PK);
|
|
114
154
|
}
|
|
115
155
|
exports.isAssetAddress = isAssetAddress;
|
|
156
|
+
function isGrouplessAddress(address) {
|
|
157
|
+
const addressType = decodeAndValidateAddress(address)[0];
|
|
158
|
+
return addressType === AddressType.P2PK;
|
|
159
|
+
}
|
|
160
|
+
exports.isGrouplessAddress = isGrouplessAddress;
|
|
161
|
+
function isGrouplessAddressWithoutGroupIndex(address) {
|
|
162
|
+
return !hasExplicitGroupIndex(address) && isGrouplessAddress(address);
|
|
163
|
+
}
|
|
164
|
+
exports.isGrouplessAddressWithoutGroupIndex = isGrouplessAddressWithoutGroupIndex;
|
|
165
|
+
function isGrouplessAddressWithGroupIndex(address) {
|
|
166
|
+
return hasExplicitGroupIndex(address) && isGrouplessAddress(address);
|
|
167
|
+
}
|
|
168
|
+
exports.isGrouplessAddressWithGroupIndex = isGrouplessAddressWithGroupIndex;
|
|
169
|
+
function defaultGroupOfGrouplessAddress(pubKey) {
|
|
170
|
+
return pubKey[pubKey.length - 1] & 0xff % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
171
|
+
}
|
|
172
|
+
exports.defaultGroupOfGrouplessAddress = defaultGroupOfGrouplessAddress;
|
|
116
173
|
function isContractAddress(address) {
|
|
117
174
|
const addressType = decodeAndValidateAddress(address)[0];
|
|
118
175
|
return addressType === AddressType.P2C;
|
|
@@ -131,6 +188,9 @@ function groupOfAddress(address) {
|
|
|
131
188
|
else if (addressType == AddressType.P2SH) {
|
|
132
189
|
return groupOfP2shAddress(addressBody);
|
|
133
190
|
}
|
|
191
|
+
else if (addressType == AddressType.P2PK) {
|
|
192
|
+
return groupOfP2pkAddress(addressBody);
|
|
193
|
+
}
|
|
134
194
|
else {
|
|
135
195
|
// Contract Address
|
|
136
196
|
const id = contractIdFromAddress(address);
|
|
@@ -140,15 +200,18 @@ function groupOfAddress(address) {
|
|
|
140
200
|
exports.groupOfAddress = groupOfAddress;
|
|
141
201
|
// Pay to public key hash address
|
|
142
202
|
function groupOfP2pkhAddress(address) {
|
|
143
|
-
return
|
|
203
|
+
return groupFromBytes(address);
|
|
144
204
|
}
|
|
145
205
|
// Pay to multiple public key hash address
|
|
146
206
|
function groupOfP2mpkhAddress(address) {
|
|
147
|
-
return
|
|
207
|
+
return groupFromBytes(address.slice(1, 33));
|
|
208
|
+
}
|
|
209
|
+
function groupOfP2pkAddress(address) {
|
|
210
|
+
return codec_2.byteCodec.decode(address.slice(38, 39)) % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
148
211
|
}
|
|
149
212
|
// Pay to script hash address
|
|
150
213
|
function groupOfP2shAddress(address) {
|
|
151
|
-
return
|
|
214
|
+
return groupFromBytes(address);
|
|
152
215
|
}
|
|
153
216
|
function contractIdFromAddress(address) {
|
|
154
217
|
return idFromAddress(address);
|
|
@@ -177,7 +240,7 @@ function groupOfPrivateKey(privateKey, keyType) {
|
|
|
177
240
|
exports.groupOfPrivateKey = groupOfPrivateKey;
|
|
178
241
|
function publicKeyFromPrivateKey(privateKey, _keyType) {
|
|
179
242
|
const keyType = _keyType ?? 'default';
|
|
180
|
-
if (keyType === 'default') {
|
|
243
|
+
if (keyType === 'default' || keyType === 'gl-secp256k1') {
|
|
181
244
|
const key = ec.keyFromPrivate(privateKey);
|
|
182
245
|
return key.getPublic(true, 'hex');
|
|
183
246
|
}
|
|
@@ -193,6 +256,12 @@ function addressFromPublicKey(publicKey, _keyType) {
|
|
|
193
256
|
const bytes = new Uint8Array([AddressType.P2PKH, ...hash]);
|
|
194
257
|
return bs58_1.default.encode(bytes);
|
|
195
258
|
}
|
|
259
|
+
else if (keyType === 'gl-secp256k1') {
|
|
260
|
+
const publicKeyBytes = new Uint8Array([0x00, ...(0, utils_1.hexToBinUnsafe)(publicKey)]);
|
|
261
|
+
const hashBytes = codec_1.intAs4BytesCodec.encode((0, djb2_1.default)(publicKeyBytes));
|
|
262
|
+
const bytes = new Uint8Array([0x04, ...publicKeyBytes, ...hashBytes]);
|
|
263
|
+
return bs58_1.default.encode(bytes);
|
|
264
|
+
}
|
|
196
265
|
else {
|
|
197
266
|
const lockupScript = (0, utils_1.hexToBinUnsafe)(`0101000000000458144020${publicKey}8685`);
|
|
198
267
|
return addressFromScript(lockupScript);
|
|
@@ -242,13 +311,16 @@ function subContractId(parentContractId, pathInHex, group) {
|
|
|
242
311
|
exports.subContractId = subContractId;
|
|
243
312
|
function groupOfLockupScript(lockupScript) {
|
|
244
313
|
if (lockupScript.kind === 'P2PKH') {
|
|
245
|
-
return
|
|
314
|
+
return groupFromBytes(lockupScript.value);
|
|
246
315
|
}
|
|
247
316
|
else if (lockupScript.kind === 'P2MPKH') {
|
|
248
|
-
return
|
|
317
|
+
return groupFromBytes(lockupScript.value.publicKeyHashes[0]);
|
|
249
318
|
}
|
|
250
319
|
else if (lockupScript.kind === 'P2SH') {
|
|
251
|
-
return
|
|
320
|
+
return groupFromBytes(lockupScript.value);
|
|
321
|
+
}
|
|
322
|
+
else if (lockupScript.kind === 'P2PK') {
|
|
323
|
+
return lockupScript.value.group % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
252
324
|
}
|
|
253
325
|
else {
|
|
254
326
|
// P2C
|
|
@@ -257,8 +329,44 @@ function groupOfLockupScript(lockupScript) {
|
|
|
257
329
|
}
|
|
258
330
|
}
|
|
259
331
|
exports.groupOfLockupScript = groupOfLockupScript;
|
|
260
|
-
function
|
|
332
|
+
function groupFromBytes(bytes) {
|
|
261
333
|
const hint = (0, djb2_1.default)(bytes) | 1;
|
|
334
|
+
return groupFromHint(hint);
|
|
335
|
+
}
|
|
336
|
+
exports.groupFromBytes = groupFromBytes;
|
|
337
|
+
function groupFromHint(hint) {
|
|
262
338
|
const hash = (0, utils_1.xorByte)(hint);
|
|
263
339
|
return hash % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
264
340
|
}
|
|
341
|
+
exports.groupFromHint = groupFromHint;
|
|
342
|
+
function hasExplicitGroupIndex(address) {
|
|
343
|
+
return address.length > 2 && address[address.length - 2] === ':';
|
|
344
|
+
}
|
|
345
|
+
exports.hasExplicitGroupIndex = hasExplicitGroupIndex;
|
|
346
|
+
function addressWithoutExplicitGroupIndex(address) {
|
|
347
|
+
if (hasExplicitGroupIndex(address)) {
|
|
348
|
+
return address.slice(0, address.length - 2);
|
|
349
|
+
}
|
|
350
|
+
return address;
|
|
351
|
+
}
|
|
352
|
+
exports.addressWithoutExplicitGroupIndex = addressWithoutExplicitGroupIndex;
|
|
353
|
+
function addressFromLockupScript(lockupScript) {
|
|
354
|
+
if (lockupScript.kind === 'P2PK') {
|
|
355
|
+
const groupByte = lockup_script_codec_1.lockupScriptCodec.encode(lockupScript).slice(-1);
|
|
356
|
+
const address = bs58_1.default.encode(lockup_script_codec_1.lockupScriptCodec.encode(lockupScript).slice(0, -1));
|
|
357
|
+
return `${address}:${groupByte}`;
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
return bs58_1.default.encode(lockup_script_codec_1.lockupScriptCodec.encode(lockupScript));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
exports.addressFromLockupScript = addressFromLockupScript;
|
|
364
|
+
function parseGroupIndex(groupIndexStr) {
|
|
365
|
+
return validateGroupIndex(parseInt(groupIndexStr), groupIndexStr);
|
|
366
|
+
}
|
|
367
|
+
function validateGroupIndex(groupIndex, groupIndexStr) {
|
|
368
|
+
if (isNaN(groupIndex) || groupIndex < 0 || groupIndex >= constants_1.TOTAL_NUMBER_OF_GROUPS) {
|
|
369
|
+
throw new Error(`Invalid group index: ${groupIndexStr ?? groupIndex}`);
|
|
370
|
+
}
|
|
371
|
+
return groupIndex;
|
|
372
|
+
}
|
|
@@ -176,7 +176,7 @@ export interface BuildChainedDeployContractTx {
|
|
|
176
176
|
}
|
|
177
177
|
/** BuildChainedDeployContractTxResult */
|
|
178
178
|
export interface BuildChainedDeployContractTxResult {
|
|
179
|
-
value:
|
|
179
|
+
value: BuildSimpleDeployContractTxResult;
|
|
180
180
|
type: string;
|
|
181
181
|
}
|
|
182
182
|
/** BuildChainedExecuteScriptTx */
|
|
@@ -186,7 +186,7 @@ export interface BuildChainedExecuteScriptTx {
|
|
|
186
186
|
}
|
|
187
187
|
/** BuildChainedExecuteScriptTxResult */
|
|
188
188
|
export interface BuildChainedExecuteScriptTxResult {
|
|
189
|
-
value:
|
|
189
|
+
value: BuildSimpleExecuteScriptTxResult;
|
|
190
190
|
type: string;
|
|
191
191
|
}
|
|
192
192
|
/** BuildChainedTransferTx */
|
|
@@ -196,7 +196,7 @@ export interface BuildChainedTransferTx {
|
|
|
196
196
|
}
|
|
197
197
|
/** BuildChainedTransferTxResult */
|
|
198
198
|
export interface BuildChainedTransferTxResult {
|
|
199
|
-
value:
|
|
199
|
+
value: BuildSimpleTransferTxResult;
|
|
200
200
|
type: string;
|
|
201
201
|
}
|
|
202
202
|
/** BuildChainedTx */
|
|
@@ -222,25 +222,13 @@ export interface BuildDeployContractTx {
|
|
|
222
222
|
gasAmount?: number;
|
|
223
223
|
/** @format uint256 */
|
|
224
224
|
gasPrice?: string;
|
|
225
|
+
/** @format group-index */
|
|
226
|
+
group?: number;
|
|
225
227
|
/** @format block-hash */
|
|
226
228
|
targetBlockHash?: string;
|
|
227
229
|
}
|
|
228
230
|
/** BuildDeployContractTxResult */
|
|
229
|
-
export
|
|
230
|
-
/** @format int32 */
|
|
231
|
-
fromGroup: number;
|
|
232
|
-
/** @format int32 */
|
|
233
|
-
toGroup: number;
|
|
234
|
-
unsignedTx: string;
|
|
235
|
-
/** @format gas */
|
|
236
|
-
gasAmount: number;
|
|
237
|
-
/** @format uint256 */
|
|
238
|
-
gasPrice: string;
|
|
239
|
-
/** @format 32-byte-hash */
|
|
240
|
-
txId: string;
|
|
241
|
-
/** @format address */
|
|
242
|
-
contractAddress: string;
|
|
243
|
-
}
|
|
231
|
+
export type BuildDeployContractTxResult = BuildGrouplessDeployContractTxResult | BuildSimpleDeployContractTxResult;
|
|
244
232
|
/** BuildExecuteScriptTx */
|
|
245
233
|
export interface BuildExecuteScriptTx {
|
|
246
234
|
/** @format hex-string */
|
|
@@ -258,23 +246,30 @@ export interface BuildExecuteScriptTx {
|
|
|
258
246
|
gasPrice?: string;
|
|
259
247
|
/** @format block-hash */
|
|
260
248
|
targetBlockHash?: string;
|
|
249
|
+
/** @format group-index */
|
|
250
|
+
group?: number;
|
|
261
251
|
/** @format double */
|
|
262
252
|
gasEstimationMultiplier?: number;
|
|
263
253
|
}
|
|
264
254
|
/** BuildExecuteScriptTxResult */
|
|
265
|
-
export
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
255
|
+
export type BuildExecuteScriptTxResult = BuildGrouplessExecuteScriptTxResult | BuildSimpleExecuteScriptTxResult;
|
|
256
|
+
/** BuildGrouplessDeployContractTxResult */
|
|
257
|
+
export interface BuildGrouplessDeployContractTxResult {
|
|
258
|
+
transferTxs: BuildSimpleTransferTxResult[];
|
|
259
|
+
deployContractTx: BuildSimpleDeployContractTxResult;
|
|
260
|
+
type: string;
|
|
261
|
+
}
|
|
262
|
+
/** BuildGrouplessExecuteScriptTxResult */
|
|
263
|
+
export interface BuildGrouplessExecuteScriptTxResult {
|
|
264
|
+
transferTxs: BuildSimpleTransferTxResult[];
|
|
265
|
+
executeScriptTx: BuildSimpleExecuteScriptTxResult;
|
|
266
|
+
type: string;
|
|
267
|
+
}
|
|
268
|
+
/** BuildGrouplessTransferTxResult */
|
|
269
|
+
export interface BuildGrouplessTransferTxResult {
|
|
270
|
+
transferTxs: BuildSimpleTransferTxResult[];
|
|
271
|
+
transferTx: BuildSimpleTransferTxResult;
|
|
272
|
+
type: string;
|
|
278
273
|
}
|
|
279
274
|
/** BuildInfo */
|
|
280
275
|
export interface BuildInfo {
|
|
@@ -311,6 +306,54 @@ export interface BuildMultisigAddressResult {
|
|
|
311
306
|
/** @format address */
|
|
312
307
|
address: string;
|
|
313
308
|
}
|
|
309
|
+
/** BuildSimpleDeployContractTxResult */
|
|
310
|
+
export interface BuildSimpleDeployContractTxResult {
|
|
311
|
+
/** @format int32 */
|
|
312
|
+
fromGroup: number;
|
|
313
|
+
/** @format int32 */
|
|
314
|
+
toGroup: number;
|
|
315
|
+
unsignedTx: string;
|
|
316
|
+
/** @format gas */
|
|
317
|
+
gasAmount: number;
|
|
318
|
+
/** @format uint256 */
|
|
319
|
+
gasPrice: string;
|
|
320
|
+
/** @format 32-byte-hash */
|
|
321
|
+
txId: string;
|
|
322
|
+
/** @format address */
|
|
323
|
+
contractAddress: string;
|
|
324
|
+
type: string;
|
|
325
|
+
}
|
|
326
|
+
/** BuildSimpleExecuteScriptTxResult */
|
|
327
|
+
export interface BuildSimpleExecuteScriptTxResult {
|
|
328
|
+
/** @format int32 */
|
|
329
|
+
fromGroup: number;
|
|
330
|
+
/** @format int32 */
|
|
331
|
+
toGroup: number;
|
|
332
|
+
unsignedTx: string;
|
|
333
|
+
/** @format gas */
|
|
334
|
+
gasAmount: number;
|
|
335
|
+
/** @format uint256 */
|
|
336
|
+
gasPrice: string;
|
|
337
|
+
/** @format 32-byte-hash */
|
|
338
|
+
txId: string;
|
|
339
|
+
simulationResult: SimulationResult;
|
|
340
|
+
type: string;
|
|
341
|
+
}
|
|
342
|
+
/** BuildSimpleTransferTxResult */
|
|
343
|
+
export interface BuildSimpleTransferTxResult {
|
|
344
|
+
unsignedTx: string;
|
|
345
|
+
/** @format gas */
|
|
346
|
+
gasAmount: number;
|
|
347
|
+
/** @format uint256 */
|
|
348
|
+
gasPrice: string;
|
|
349
|
+
/** @format 32-byte-hash */
|
|
350
|
+
txId: string;
|
|
351
|
+
/** @format int32 */
|
|
352
|
+
fromGroup: number;
|
|
353
|
+
/** @format int32 */
|
|
354
|
+
toGroup: number;
|
|
355
|
+
type: string;
|
|
356
|
+
}
|
|
314
357
|
/** BuildSweepAddressTransactions */
|
|
315
358
|
export interface BuildSweepAddressTransactions {
|
|
316
359
|
/** @format public-key */
|
|
@@ -370,23 +413,13 @@ export interface BuildTransferTx {
|
|
|
370
413
|
gasAmount?: number;
|
|
371
414
|
/** @format uint256 */
|
|
372
415
|
gasPrice?: string;
|
|
416
|
+
/** @format group-index */
|
|
417
|
+
group?: number;
|
|
373
418
|
/** @format block-hash */
|
|
374
419
|
targetBlockHash?: string;
|
|
375
420
|
}
|
|
376
421
|
/** BuildTransferTxResult */
|
|
377
|
-
export
|
|
378
|
-
unsignedTx: string;
|
|
379
|
-
/** @format gas */
|
|
380
|
-
gasAmount: number;
|
|
381
|
-
/** @format uint256 */
|
|
382
|
-
gasPrice: string;
|
|
383
|
-
/** @format 32-byte-hash */
|
|
384
|
-
txId: string;
|
|
385
|
-
/** @format int32 */
|
|
386
|
-
fromGroup: number;
|
|
387
|
-
/** @format int32 */
|
|
388
|
-
toGroup: number;
|
|
389
|
-
}
|
|
422
|
+
export type BuildTransferTxResult = BuildGrouplessTransferTxResult | BuildSimpleTransferTxResult;
|
|
390
423
|
/** CallContract */
|
|
391
424
|
export interface CallContract {
|
|
392
425
|
/** @format int32 */
|
|
@@ -1082,6 +1115,7 @@ export interface TestContract {
|
|
|
1082
1115
|
args?: Val[];
|
|
1083
1116
|
existingContracts?: ContractState[];
|
|
1084
1117
|
inputAssets?: TestInputAsset[];
|
|
1118
|
+
dustAmount?: string;
|
|
1085
1119
|
}
|
|
1086
1120
|
/** TestContractResult */
|
|
1087
1121
|
export interface TestContractResult {
|
|
@@ -1858,7 +1892,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1858
1892
|
* @summary Build an unsigned transfer transaction to a number of recipients
|
|
1859
1893
|
* @request POST:/transactions/build
|
|
1860
1894
|
*/
|
|
1861
|
-
postTransactionsBuild: (data: BuildTransferTx, params?: RequestParams) => Promise<
|
|
1895
|
+
postTransactionsBuild: (data: BuildTransferTx, params?: RequestParams) => Promise<BuildSimpleTransferTxResult | BuildGrouplessTransferTxResult>;
|
|
1862
1896
|
/**
|
|
1863
1897
|
* No description
|
|
1864
1898
|
*
|
|
@@ -1867,7 +1901,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1867
1901
|
* @summary Build unsigned transfer transactions from an address of one group to addresses of many groups. Each target group requires a dedicated transaction or more in case large number of outputs needed to be split.
|
|
1868
1902
|
* @request POST:/transactions/build-transfer-from-one-to-many-groups
|
|
1869
1903
|
*/
|
|
1870
|
-
postTransactionsBuildTransferFromOneToManyGroups: (data: BuildTransferTx, params?: RequestParams) => Promise<
|
|
1904
|
+
postTransactionsBuildTransferFromOneToManyGroups: (data: BuildTransferTx, params?: RequestParams) => Promise<BuildSimpleTransferTxResult[]>;
|
|
1871
1905
|
/**
|
|
1872
1906
|
* No description
|
|
1873
1907
|
*
|
|
@@ -1876,7 +1910,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1876
1910
|
* @summary Build an unsigned transaction with multiple addresses to a number of recipients
|
|
1877
1911
|
* @request POST:/transactions/build-multi-addresses
|
|
1878
1912
|
*/
|
|
1879
|
-
postTransactionsBuildMultiAddresses: (data: BuildMultiAddressesTransaction, params?: RequestParams) => Promise<
|
|
1913
|
+
postTransactionsBuildMultiAddresses: (data: BuildMultiAddressesTransaction, params?: RequestParams) => Promise<BuildSimpleTransferTxResult>;
|
|
1880
1914
|
/**
|
|
1881
1915
|
* No description
|
|
1882
1916
|
*
|
|
@@ -2045,7 +2079,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
2045
2079
|
* @summary Build an unsigned script
|
|
2046
2080
|
* @request POST:/contracts/unsigned-tx/execute-script
|
|
2047
2081
|
*/
|
|
2048
|
-
postContractsUnsignedTxExecuteScript: (data: BuildExecuteScriptTx, params?: RequestParams) => Promise<
|
|
2082
|
+
postContractsUnsignedTxExecuteScript: (data: BuildExecuteScriptTx, params?: RequestParams) => Promise<BuildSimpleExecuteScriptTxResult | BuildGrouplessExecuteScriptTxResult>;
|
|
2049
2083
|
/**
|
|
2050
2084
|
* No description
|
|
2051
2085
|
*
|
|
@@ -2072,7 +2106,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
2072
2106
|
* @summary Build an unsigned contract
|
|
2073
2107
|
* @request POST:/contracts/unsigned-tx/deploy-contract
|
|
2074
2108
|
*/
|
|
2075
|
-
postContractsUnsignedTxDeployContract: (data: BuildDeployContractTx, params?: RequestParams) => Promise<
|
|
2109
|
+
postContractsUnsignedTxDeployContract: (data: BuildDeployContractTx, params?: RequestParams) => Promise<BuildSimpleDeployContractTxResult | BuildGrouplessDeployContractTxResult>;
|
|
2076
2110
|
/**
|
|
2077
2111
|
* No description
|
|
2078
2112
|
*
|
|
@@ -2178,7 +2212,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
2178
2212
|
* @summary Build a multisig unsigned transaction
|
|
2179
2213
|
* @request POST:/multisig/build
|
|
2180
2214
|
*/
|
|
2181
|
-
postMultisigBuild: (data: BuildMultisig, params?: RequestParams) => Promise<
|
|
2215
|
+
postMultisigBuild: (data: BuildMultisig, params?: RequestParams) => Promise<BuildSimpleTransferTxResult>;
|
|
2182
2216
|
/**
|
|
2183
2217
|
* No description
|
|
2184
2218
|
*
|
package/dist/src/api/types.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare function toApiNumber256(v: Val): string;
|
|
|
18
18
|
export declare function toApiNumber256Optional(v?: Val): string | undefined;
|
|
19
19
|
export declare function fromApiNumber256(n: string): bigint;
|
|
20
20
|
export declare function toApiByteVec(v: Val): string;
|
|
21
|
-
export declare function toApiAddress(
|
|
21
|
+
export declare function toApiAddress(v0: Val): string;
|
|
22
22
|
export declare function toApiArray(tpe: string, v: Val): node.Val;
|
|
23
23
|
export declare function toApiVal(v: Val, tpe: string): node.Val;
|
|
24
24
|
export declare function fromApiPrimitiveVal(value: node.Val, tpe: string, systemEvent?: boolean): Val;
|
package/dist/src/api/types.js
CHANGED
|
@@ -18,6 +18,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.StdInterfaceIds = exports.request = exports.requestWithLog = exports.forwardRequests = exports.getDefaultPrimitiveValue = exports.decodeArrayType = exports.fromApiPrimitiveVal = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = exports.PrimitiveTypes = void 0;
|
|
21
|
+
const address_1 = require("../address");
|
|
21
22
|
const constants_1 = require("../constants");
|
|
22
23
|
const debug_1 = require("../debug");
|
|
23
24
|
const error_1 = require("../error");
|
|
@@ -91,15 +92,19 @@ function toApiByteVec(v) {
|
|
|
91
92
|
throw new Error(`Invalid hex-string: ${v}`);
|
|
92
93
|
}
|
|
93
94
|
exports.toApiByteVec = toApiByteVec;
|
|
94
|
-
function toApiAddress(
|
|
95
|
-
if (typeof
|
|
95
|
+
function toApiAddress(v0) {
|
|
96
|
+
if (typeof v0 === 'string') {
|
|
97
|
+
let v = v0;
|
|
98
|
+
if ((0, address_1.hasExplicitGroupIndex)(v)) {
|
|
99
|
+
v = v.slice(0, -2);
|
|
100
|
+
}
|
|
96
101
|
if ((0, utils_1.isBase58)(v)) {
|
|
97
|
-
return
|
|
102
|
+
return v0;
|
|
98
103
|
}
|
|
99
|
-
throw new Error(`Invalid base58 string: ${
|
|
104
|
+
throw new Error(`Invalid base58 string: ${v0}`);
|
|
100
105
|
}
|
|
101
106
|
else {
|
|
102
|
-
throw new Error(`Invalid value: ${
|
|
107
|
+
throw new Error(`Invalid value: ${v0}, expected a base58 string`);
|
|
103
108
|
}
|
|
104
109
|
}
|
|
105
110
|
exports.toApiAddress = toApiAddress;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import { EnumCodec } from './codec';
|
|
1
|
+
import { EnumCodec, FixedSizeCodec } from './codec';
|
|
2
2
|
export type PublicKeyHash = Uint8Array;
|
|
3
3
|
export type P2PKH = Uint8Array;
|
|
4
4
|
export type P2SH = Uint8Array;
|
|
5
5
|
export type P2C = Uint8Array;
|
|
6
|
-
export declare const p2cCodec:
|
|
6
|
+
export declare const p2cCodec: FixedSizeCodec;
|
|
7
7
|
export interface P2MPKH {
|
|
8
8
|
publicKeyHashes: PublicKeyHash[];
|
|
9
9
|
m: number;
|
|
10
10
|
}
|
|
11
|
+
export interface P2PC {
|
|
12
|
+
type: number;
|
|
13
|
+
publicKey: Uint8Array;
|
|
14
|
+
checkSum: Uint8Array;
|
|
15
|
+
group: number;
|
|
16
|
+
}
|
|
11
17
|
export type LockupScript = {
|
|
12
18
|
kind: 'P2PKH';
|
|
13
19
|
value: P2PKH;
|
|
@@ -20,5 +26,8 @@ export type LockupScript = {
|
|
|
20
26
|
} | {
|
|
21
27
|
kind: 'P2C';
|
|
22
28
|
value: P2C;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'P2PK';
|
|
31
|
+
value: P2PC;
|
|
23
32
|
};
|
|
24
33
|
export declare const lockupScriptCodec: EnumCodec<LockupScript>;
|
|
@@ -26,9 +26,16 @@ const p2mpkhCodec = new codec_1.ObjectCodec({
|
|
|
26
26
|
publicKeyHashes: new array_codec_1.ArrayCodec(codec_1.byte32Codec),
|
|
27
27
|
m: compact_int_codec_1.i32Codec
|
|
28
28
|
});
|
|
29
|
+
const p2pkCodec = new codec_1.ObjectCodec({
|
|
30
|
+
type: codec_1.byteCodec,
|
|
31
|
+
publicKey: new codec_1.FixedSizeCodec(33),
|
|
32
|
+
checkSum: new codec_1.FixedSizeCodec(4),
|
|
33
|
+
group: codec_1.byteCodec
|
|
34
|
+
});
|
|
29
35
|
exports.lockupScriptCodec = new codec_1.EnumCodec('lockup script', {
|
|
30
36
|
P2PKH: codec_1.byte32Codec,
|
|
31
37
|
P2MPKH: p2mpkhCodec,
|
|
32
38
|
P2SH: codec_1.byte32Codec,
|
|
33
|
-
P2C: codec_1.byte32Codec
|
|
39
|
+
P2C: codec_1.byte32Codec,
|
|
40
|
+
P2PK: p2pkCodec
|
|
34
41
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EnumCodec } from './codec';
|
|
2
2
|
import { Script } from './script-codec';
|
|
3
3
|
import { Val } from './val';
|
|
4
|
-
export type
|
|
4
|
+
export type PublicKey = Uint8Array;
|
|
5
5
|
export interface KeyWithIndex {
|
|
6
|
-
publicKey:
|
|
6
|
+
publicKey: PublicKey;
|
|
7
7
|
index: number;
|
|
8
8
|
}
|
|
9
9
|
export type P2MPKH = KeyWithIndex[];
|
|
@@ -12,9 +12,11 @@ export interface P2SH {
|
|
|
12
12
|
params: Val[];
|
|
13
13
|
}
|
|
14
14
|
export type SameAsPrevious = 'SameAsPrevious';
|
|
15
|
+
export type P2PK = 'P2PK';
|
|
16
|
+
export type KeyType = number;
|
|
15
17
|
export type UnlockScript = {
|
|
16
18
|
kind: 'P2PKH';
|
|
17
|
-
value:
|
|
19
|
+
value: PublicKey;
|
|
18
20
|
} | {
|
|
19
21
|
kind: 'P2MPKH';
|
|
20
22
|
value: P2MPKH;
|
|
@@ -24,6 +26,12 @@ export type UnlockScript = {
|
|
|
24
26
|
} | {
|
|
25
27
|
kind: 'SameAsPrevious';
|
|
26
28
|
value: SameAsPrevious;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'PoLW';
|
|
31
|
+
value: PublicKey;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'P2PK';
|
|
34
|
+
value: P2PK;
|
|
27
35
|
};
|
|
28
36
|
export declare const unlockScriptCodec: EnumCodec<UnlockScript>;
|
|
29
37
|
export declare const encodedSameAsPrevious: Uint8Array;
|
|
@@ -23,9 +23,9 @@ const compact_int_codec_1 = require("./compact-int-codec");
|
|
|
23
23
|
const codec_1 = require("./codec");
|
|
24
24
|
const script_codec_1 = require("./script-codec");
|
|
25
25
|
const val_1 = require("./val");
|
|
26
|
-
const
|
|
26
|
+
const publicKeyCodec = new codec_1.FixedSizeCodec(33);
|
|
27
27
|
const keyWithIndexCodec = new codec_1.ObjectCodec({
|
|
28
|
-
publicKey:
|
|
28
|
+
publicKey: publicKeyCodec,
|
|
29
29
|
index: compact_int_codec_1.i32Codec
|
|
30
30
|
});
|
|
31
31
|
const p2mpkhCodec = new array_codec_1.ArrayCodec(keyWithIndexCodec);
|
|
@@ -41,10 +41,20 @@ const sameAsPreviousCodec = new (class extends codec_1.Codec {
|
|
|
41
41
|
return 'SameAsPrevious';
|
|
42
42
|
}
|
|
43
43
|
})();
|
|
44
|
+
const p2pkCodec = new (class extends codec_1.Codec {
|
|
45
|
+
encode() {
|
|
46
|
+
return new Uint8Array([]);
|
|
47
|
+
}
|
|
48
|
+
_decode() {
|
|
49
|
+
return 'P2PK';
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
44
52
|
exports.unlockScriptCodec = new codec_1.EnumCodec('unlock script', {
|
|
45
|
-
P2PKH:
|
|
53
|
+
P2PKH: publicKeyCodec,
|
|
46
54
|
P2MPKH: p2mpkhCodec,
|
|
47
55
|
P2SH: p2shCodec,
|
|
48
|
-
SameAsPrevious: sameAsPreviousCodec
|
|
56
|
+
SameAsPrevious: sameAsPreviousCodec,
|
|
57
|
+
PoLW: publicKeyCodec,
|
|
58
|
+
P2PK: p2pkCodec
|
|
49
59
|
});
|
|
50
60
|
exports.encodedSameAsPrevious = exports.unlockScriptCodec.encode({ kind: 'SameAsPrevious', value: 'SameAsPrevious' });
|