@alephium/web3 1.11.5 → 1.12.0-beta.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 +11 -1
- package/dist/src/address/address.js +117 -11
- package/dist/src/api/api-alephium.d.ts +101 -4
- package/dist/src/api/api-alephium.js +51 -1
- package/dist/src/api/node-provider.d.ts +2 -0
- package/dist/src/api/node-provider.js +1 -0
- 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 +3 -3
- package/dist/src/contract/contract.js +12 -5
- package/dist/src/contract/ralph.js +2 -1
- package/dist/src/signer/signer.js +1 -1
- package/dist/src/signer/tx-builder.d.ts +7 -1
- package/dist/src/signer/tx-builder.js +67 -0
- package/dist/src/signer/types.d.ts +29 -2
- package/dist/src/signer/types.js +3 -0
- package/dist/src/utils/sign.js +2 -2
- package/dist/src/utils/webcrypto.d.ts +3 -1
- package/package.json +3 -3
- package/src/address/address.ts +120 -12
- package/src/api/api-alephium.ts +474 -144
- package/src/api/node-provider.ts +3 -0
- 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 +33 -10
- package/src/contract/ralph.ts +5 -2
- package/src/signer/signer.ts +1 -1
- package/src/signer/tx-builder.ts +88 -1
- package/src/signer/types.ts +36 -2
- 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,7 @@ 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 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.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,73 @@ function decodeAndValidateAddress(address) {
|
|
|
106
108
|
if (decoded.length === 33)
|
|
107
109
|
return decoded;
|
|
108
110
|
}
|
|
111
|
+
else if (isGrouplessAddressWithGroup(decoded)) {
|
|
112
|
+
// [type, keyType, ...publicKey, ...checkSum, ...groupByte]
|
|
113
|
+
const publicKeyToIndex = decoded.length - 1 - 4;
|
|
114
|
+
const publicKeyLikeBytes = decoded.slice(1, publicKeyToIndex);
|
|
115
|
+
const checksum = (0, utils_1.binToHex)(decoded.slice(publicKeyToIndex, publicKeyToIndex + 4));
|
|
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(decoded.length - 1, decoded.length));
|
|
121
|
+
validateGroupIndex(group);
|
|
122
|
+
return decoded;
|
|
123
|
+
}
|
|
109
124
|
throw new Error(`Invalid address: ${address}`);
|
|
110
125
|
}
|
|
126
|
+
function isGrouplessAddressWithoutGroup(decoded) {
|
|
127
|
+
return decoded[0] === AddressType.P2PK && (decoded.length === 38 || decoded.length === 39);
|
|
128
|
+
}
|
|
129
|
+
function isGrouplessAddressWithGroup(decoded) {
|
|
130
|
+
return decoded[0] === AddressType.P2PK && (decoded.length === 39 || decoded.length === 40);
|
|
131
|
+
}
|
|
132
|
+
function addressToBytes(address) {
|
|
133
|
+
if (hasExplicitGroupIndex(address)) {
|
|
134
|
+
const groupIndex = parseGroupIndex(address[address.length - 1]);
|
|
135
|
+
const decoded = (0, bs58_1.base58ToBytes)(address.slice(0, address.length - 2));
|
|
136
|
+
if (isGrouplessAddressWithoutGroup(decoded)) {
|
|
137
|
+
const groupByte = codec_2.byteCodec.encode(groupIndex);
|
|
138
|
+
return new Uint8Array([...decoded, ...groupByte]);
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`Invalid groupless address: ${address}`);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
const decoded = (0, bs58_1.base58ToBytes)(address);
|
|
144
|
+
if (isGrouplessAddressWithoutGroup(decoded)) {
|
|
145
|
+
const group = defaultGroupOfGrouplessAddress(decoded.slice(2, decoded.length - 4));
|
|
146
|
+
const groupByte = codec_2.byteCodec.encode(group);
|
|
147
|
+
return new Uint8Array([...decoded, ...groupByte]);
|
|
148
|
+
}
|
|
149
|
+
return decoded;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.addressToBytes = addressToBytes;
|
|
111
153
|
function isAssetAddress(address) {
|
|
112
154
|
const addressType = decodeAndValidateAddress(address)[0];
|
|
113
|
-
return addressType === AddressType.P2PKH ||
|
|
155
|
+
return (addressType === AddressType.P2PKH ||
|
|
156
|
+
addressType === AddressType.P2MPKH ||
|
|
157
|
+
addressType === AddressType.P2SH ||
|
|
158
|
+
addressType === AddressType.P2PK);
|
|
114
159
|
}
|
|
115
160
|
exports.isAssetAddress = isAssetAddress;
|
|
161
|
+
function isGrouplessAddress(address) {
|
|
162
|
+
const addressType = decodeAndValidateAddress(address)[0];
|
|
163
|
+
return addressType === AddressType.P2PK;
|
|
164
|
+
}
|
|
165
|
+
exports.isGrouplessAddress = isGrouplessAddress;
|
|
166
|
+
function isGrouplessAddressWithoutGroupIndex(address) {
|
|
167
|
+
return !hasExplicitGroupIndex(address) && isGrouplessAddress(address);
|
|
168
|
+
}
|
|
169
|
+
exports.isGrouplessAddressWithoutGroupIndex = isGrouplessAddressWithoutGroupIndex;
|
|
170
|
+
function isGrouplessAddressWithGroupIndex(address) {
|
|
171
|
+
return hasExplicitGroupIndex(address) && isGrouplessAddress(address);
|
|
172
|
+
}
|
|
173
|
+
exports.isGrouplessAddressWithGroupIndex = isGrouplessAddressWithGroupIndex;
|
|
174
|
+
function defaultGroupOfGrouplessAddress(pubKey) {
|
|
175
|
+
return pubKey[pubKey.length - 1] & 0xff % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
176
|
+
}
|
|
177
|
+
exports.defaultGroupOfGrouplessAddress = defaultGroupOfGrouplessAddress;
|
|
116
178
|
function isContractAddress(address) {
|
|
117
179
|
const addressType = decodeAndValidateAddress(address)[0];
|
|
118
180
|
return addressType === AddressType.P2C;
|
|
@@ -131,6 +193,9 @@ function groupOfAddress(address) {
|
|
|
131
193
|
else if (addressType == AddressType.P2SH) {
|
|
132
194
|
return groupOfP2shAddress(addressBody);
|
|
133
195
|
}
|
|
196
|
+
else if (addressType == AddressType.P2PK) {
|
|
197
|
+
return groupOfP2pkAddress(addressBody);
|
|
198
|
+
}
|
|
134
199
|
else {
|
|
135
200
|
// Contract Address
|
|
136
201
|
const id = contractIdFromAddress(address);
|
|
@@ -140,15 +205,18 @@ function groupOfAddress(address) {
|
|
|
140
205
|
exports.groupOfAddress = groupOfAddress;
|
|
141
206
|
// Pay to public key hash address
|
|
142
207
|
function groupOfP2pkhAddress(address) {
|
|
143
|
-
return
|
|
208
|
+
return groupFromBytes(address);
|
|
144
209
|
}
|
|
145
210
|
// Pay to multiple public key hash address
|
|
146
211
|
function groupOfP2mpkhAddress(address) {
|
|
147
|
-
return
|
|
212
|
+
return groupFromBytes(address.slice(1, 33));
|
|
213
|
+
}
|
|
214
|
+
function groupOfP2pkAddress(address) {
|
|
215
|
+
return codec_2.byteCodec.decode(address.slice(38, 39)) % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
148
216
|
}
|
|
149
217
|
// Pay to script hash address
|
|
150
218
|
function groupOfP2shAddress(address) {
|
|
151
|
-
return
|
|
219
|
+
return groupFromBytes(address);
|
|
152
220
|
}
|
|
153
221
|
function contractIdFromAddress(address) {
|
|
154
222
|
return idFromAddress(address);
|
|
@@ -177,7 +245,7 @@ function groupOfPrivateKey(privateKey, keyType) {
|
|
|
177
245
|
exports.groupOfPrivateKey = groupOfPrivateKey;
|
|
178
246
|
function publicKeyFromPrivateKey(privateKey, _keyType) {
|
|
179
247
|
const keyType = _keyType ?? 'default';
|
|
180
|
-
if (keyType === 'default') {
|
|
248
|
+
if (keyType === 'default' || keyType === 'groupless') {
|
|
181
249
|
const key = ec.keyFromPrivate(privateKey);
|
|
182
250
|
return key.getPublic(true, 'hex');
|
|
183
251
|
}
|
|
@@ -193,6 +261,12 @@ function addressFromPublicKey(publicKey, _keyType) {
|
|
|
193
261
|
const bytes = new Uint8Array([AddressType.P2PKH, ...hash]);
|
|
194
262
|
return bs58_1.default.encode(bytes);
|
|
195
263
|
}
|
|
264
|
+
else if (keyType === 'groupless') {
|
|
265
|
+
const publicKeyBytes = new Uint8Array([0x00, ...(0, utils_1.hexToBinUnsafe)(publicKey)]);
|
|
266
|
+
const hashBytes = codec_1.intAs4BytesCodec.encode((0, djb2_1.default)(publicKeyBytes));
|
|
267
|
+
const bytes = new Uint8Array([0x04, ...publicKeyBytes, ...hashBytes]);
|
|
268
|
+
return bs58_1.default.encode(bytes);
|
|
269
|
+
}
|
|
196
270
|
else {
|
|
197
271
|
const lockupScript = (0, utils_1.hexToBinUnsafe)(`0101000000000458144020${publicKey}8685`);
|
|
198
272
|
return addressFromScript(lockupScript);
|
|
@@ -242,13 +316,16 @@ function subContractId(parentContractId, pathInHex, group) {
|
|
|
242
316
|
exports.subContractId = subContractId;
|
|
243
317
|
function groupOfLockupScript(lockupScript) {
|
|
244
318
|
if (lockupScript.kind === 'P2PKH') {
|
|
245
|
-
return
|
|
319
|
+
return groupFromBytes(lockupScript.value);
|
|
246
320
|
}
|
|
247
321
|
else if (lockupScript.kind === 'P2MPKH') {
|
|
248
|
-
return
|
|
322
|
+
return groupFromBytes(lockupScript.value.publicKeyHashes[0]);
|
|
249
323
|
}
|
|
250
324
|
else if (lockupScript.kind === 'P2SH') {
|
|
251
|
-
return
|
|
325
|
+
return groupFromBytes(lockupScript.value);
|
|
326
|
+
}
|
|
327
|
+
else if (lockupScript.kind === 'P2PK') {
|
|
328
|
+
return lockupScript.value.group % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
252
329
|
}
|
|
253
330
|
else {
|
|
254
331
|
// P2C
|
|
@@ -257,8 +334,37 @@ function groupOfLockupScript(lockupScript) {
|
|
|
257
334
|
}
|
|
258
335
|
}
|
|
259
336
|
exports.groupOfLockupScript = groupOfLockupScript;
|
|
260
|
-
function
|
|
337
|
+
function groupFromBytes(bytes) {
|
|
261
338
|
const hint = (0, djb2_1.default)(bytes) | 1;
|
|
339
|
+
return groupFromHint(hint);
|
|
340
|
+
}
|
|
341
|
+
exports.groupFromBytes = groupFromBytes;
|
|
342
|
+
function groupFromHint(hint) {
|
|
262
343
|
const hash = (0, utils_1.xorByte)(hint);
|
|
263
344
|
return hash % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
264
345
|
}
|
|
346
|
+
exports.groupFromHint = groupFromHint;
|
|
347
|
+
function hasExplicitGroupIndex(address) {
|
|
348
|
+
return address.length > 2 && address[address.length - 2] === ':';
|
|
349
|
+
}
|
|
350
|
+
exports.hasExplicitGroupIndex = hasExplicitGroupIndex;
|
|
351
|
+
function addressFromLockupScript(lockupScript) {
|
|
352
|
+
if (lockupScript.kind === 'P2PK') {
|
|
353
|
+
const groupByte = lockup_script_codec_1.lockupScriptCodec.encode(lockupScript).slice(-1);
|
|
354
|
+
const address = bs58_1.default.encode(lockup_script_codec_1.lockupScriptCodec.encode(lockupScript).slice(0, -1));
|
|
355
|
+
return `${address}:${groupByte}`;
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
return bs58_1.default.encode(lockup_script_codec_1.lockupScriptCodec.encode(lockupScript));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
exports.addressFromLockupScript = addressFromLockupScript;
|
|
362
|
+
function parseGroupIndex(groupIndexStr) {
|
|
363
|
+
return validateGroupIndex(parseInt(groupIndexStr), groupIndexStr);
|
|
364
|
+
}
|
|
365
|
+
function validateGroupIndex(groupIndex, groupIndexStr) {
|
|
366
|
+
if (isNaN(groupIndex) || groupIndex < 0 || groupIndex >= constants_1.TOTAL_NUMBER_OF_GROUPS) {
|
|
367
|
+
throw new Error(`Invalid group index: ${groupIndexStr ?? groupIndex}`);
|
|
368
|
+
}
|
|
369
|
+
return groupIndex;
|
|
370
|
+
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/** AddressAssetState */
|
|
2
|
+
export interface AddressAssetState {
|
|
3
|
+
/** @format address */
|
|
4
|
+
address: string;
|
|
5
|
+
/** @format uint256 */
|
|
6
|
+
attoAlphAmount: string;
|
|
7
|
+
tokens?: Token[];
|
|
8
|
+
}
|
|
1
9
|
/** AddressBalance */
|
|
2
10
|
export interface AddressBalance {
|
|
3
11
|
/** @format address */
|
|
@@ -266,7 +274,58 @@ export interface BuildExecuteScriptTxResult {
|
|
|
266
274
|
gasPrice: string;
|
|
267
275
|
/** @format 32-byte-hash */
|
|
268
276
|
txId: string;
|
|
269
|
-
|
|
277
|
+
simulationResult: SimulationResult;
|
|
278
|
+
}
|
|
279
|
+
/** BuildGrouplessDeployContractTx */
|
|
280
|
+
export interface BuildGrouplessDeployContractTx {
|
|
281
|
+
fromAddress: string;
|
|
282
|
+
/** @format hex-string */
|
|
283
|
+
bytecode: string;
|
|
284
|
+
/** @format uint256 */
|
|
285
|
+
initialAttoAlphAmount?: string;
|
|
286
|
+
initialTokenAmounts?: Token[];
|
|
287
|
+
/** @format uint256 */
|
|
288
|
+
issueTokenAmount?: string;
|
|
289
|
+
/** @format address */
|
|
290
|
+
issueTokenTo?: string;
|
|
291
|
+
/** @format uint256 */
|
|
292
|
+
gasPrice?: string;
|
|
293
|
+
/** @format block-hash */
|
|
294
|
+
targetBlockHash?: string;
|
|
295
|
+
}
|
|
296
|
+
/** BuildGrouplessDeployContractTxResult */
|
|
297
|
+
export interface BuildGrouplessDeployContractTxResult {
|
|
298
|
+
transferTxs: BuildTransferTxResult[];
|
|
299
|
+
deployContractTx: BuildDeployContractTxResult;
|
|
300
|
+
}
|
|
301
|
+
/** BuildGrouplessExecuteScriptTx */
|
|
302
|
+
export interface BuildGrouplessExecuteScriptTx {
|
|
303
|
+
fromAddress: string;
|
|
304
|
+
/** @format hex-string */
|
|
305
|
+
bytecode: string;
|
|
306
|
+
/** @format uint256 */
|
|
307
|
+
attoAlphAmount?: string;
|
|
308
|
+
tokens?: Token[];
|
|
309
|
+
/** @format uint256 */
|
|
310
|
+
gasPrice?: string;
|
|
311
|
+
/** @format block-hash */
|
|
312
|
+
targetBlockHash?: string;
|
|
313
|
+
/** @format double */
|
|
314
|
+
gasEstimationMultiplier?: number;
|
|
315
|
+
}
|
|
316
|
+
/** BuildGrouplessExecuteScriptTxResult */
|
|
317
|
+
export interface BuildGrouplessExecuteScriptTxResult {
|
|
318
|
+
transferTxs: BuildTransferTxResult[];
|
|
319
|
+
executeScriptTx: BuildExecuteScriptTxResult;
|
|
320
|
+
}
|
|
321
|
+
/** BuildGrouplessTransferTx */
|
|
322
|
+
export interface BuildGrouplessTransferTx {
|
|
323
|
+
fromAddress: string;
|
|
324
|
+
destinations: Destination[];
|
|
325
|
+
/** @format uint256 */
|
|
326
|
+
gasPrice?: string;
|
|
327
|
+
/** @format block-hash */
|
|
328
|
+
targetBlockHash?: string;
|
|
270
329
|
}
|
|
271
330
|
/** BuildInfo */
|
|
272
331
|
export interface BuildInfo {
|
|
@@ -634,7 +693,7 @@ export interface Destination {
|
|
|
634
693
|
/** @format address */
|
|
635
694
|
address: string;
|
|
636
695
|
/** @format uint256 */
|
|
637
|
-
attoAlphAmount
|
|
696
|
+
attoAlphAmount?: string;
|
|
638
697
|
tokens?: Token[];
|
|
639
698
|
/** @format int64 */
|
|
640
699
|
lockTime?: number;
|
|
@@ -692,6 +751,10 @@ export interface FunctionSig {
|
|
|
692
751
|
paramIsMutable: boolean[];
|
|
693
752
|
returnTypes: string[];
|
|
694
753
|
}
|
|
754
|
+
/** GatewayTimeout */
|
|
755
|
+
export interface GatewayTimeout {
|
|
756
|
+
detail: string;
|
|
757
|
+
}
|
|
695
758
|
/** GhostUncleBlockEntry */
|
|
696
759
|
export interface GhostUncleBlockEntry {
|
|
697
760
|
/** @format block-hash */
|
|
@@ -967,6 +1030,11 @@ export interface SignResult {
|
|
|
967
1030
|
/** @format signature */
|
|
968
1031
|
signature: string;
|
|
969
1032
|
}
|
|
1033
|
+
/** SimulationResult */
|
|
1034
|
+
export interface SimulationResult {
|
|
1035
|
+
contractInputs: AddressAssetState[];
|
|
1036
|
+
generatedOutputs: AddressAssetState[];
|
|
1037
|
+
}
|
|
970
1038
|
/** Source */
|
|
971
1039
|
export interface Source {
|
|
972
1040
|
/** @format hex-string */
|
|
@@ -1054,7 +1122,7 @@ export interface TestContract {
|
|
|
1054
1122
|
/** @format address */
|
|
1055
1123
|
address?: string;
|
|
1056
1124
|
/** @format address */
|
|
1057
|
-
|
|
1125
|
+
callerContractAddress?: string;
|
|
1058
1126
|
/** @format contract */
|
|
1059
1127
|
bytecode: string;
|
|
1060
1128
|
initialImmFields?: Val[];
|
|
@@ -1325,7 +1393,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
1325
1393
|
}
|
|
1326
1394
|
/**
|
|
1327
1395
|
* @title Alephium API
|
|
1328
|
-
* @version 3.
|
|
1396
|
+
* @version 3.12.2
|
|
1329
1397
|
* @baseUrl ../
|
|
1330
1398
|
*/
|
|
1331
1399
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -2306,5 +2374,34 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
2306
2374
|
*/
|
|
2307
2375
|
putUtilsCheckHashIndexing: (params?: RequestParams) => Promise<void>;
|
|
2308
2376
|
};
|
|
2377
|
+
groupless: {
|
|
2378
|
+
/**
|
|
2379
|
+
* No description
|
|
2380
|
+
*
|
|
2381
|
+
* @tags Groupless
|
|
2382
|
+
* @name PostGrouplessTransfer
|
|
2383
|
+
* @summary Build unsigned transfer transactions from a groupless address
|
|
2384
|
+
* @request POST:/groupless/transfer
|
|
2385
|
+
*/
|
|
2386
|
+
postGrouplessTransfer: (data: BuildGrouplessTransferTx, params?: RequestParams) => Promise<BuildTransferTxResult[]>;
|
|
2387
|
+
/**
|
|
2388
|
+
* No description
|
|
2389
|
+
*
|
|
2390
|
+
* @tags Groupless
|
|
2391
|
+
* @name PostGrouplessExecuteScript
|
|
2392
|
+
* @summary Build an unsigned execute script transaction from a groupless address
|
|
2393
|
+
* @request POST:/groupless/execute-script
|
|
2394
|
+
*/
|
|
2395
|
+
postGrouplessExecuteScript: (data: BuildGrouplessExecuteScriptTx, params?: RequestParams) => Promise<BuildGrouplessExecuteScriptTxResult>;
|
|
2396
|
+
/**
|
|
2397
|
+
* No description
|
|
2398
|
+
*
|
|
2399
|
+
* @tags Groupless
|
|
2400
|
+
* @name PostGrouplessDeployContract
|
|
2401
|
+
* @summary Build an unsigned deploy contract transaction from a groupless address
|
|
2402
|
+
* @request POST:/groupless/deploy-contract
|
|
2403
|
+
*/
|
|
2404
|
+
postGrouplessDeployContract: (data: BuildGrouplessDeployContractTx, params?: RequestParams) => Promise<BuildGrouplessDeployContractTxResult>;
|
|
2405
|
+
};
|
|
2309
2406
|
}
|
|
2310
2407
|
export {};
|
|
@@ -151,7 +151,7 @@ class HttpClient {
|
|
|
151
151
|
exports.HttpClient = HttpClient;
|
|
152
152
|
/**
|
|
153
153
|
* @title Alephium API
|
|
154
|
-
* @version 3.
|
|
154
|
+
* @version 3.12.2
|
|
155
155
|
* @baseUrl ../
|
|
156
156
|
*/
|
|
157
157
|
class Api extends HttpClient {
|
|
@@ -1547,6 +1547,56 @@ class Api extends HttpClient {
|
|
|
1547
1547
|
...params
|
|
1548
1548
|
}).then(utils_1.convertHttpResponse)
|
|
1549
1549
|
};
|
|
1550
|
+
this.groupless = {
|
|
1551
|
+
/**
|
|
1552
|
+
* No description
|
|
1553
|
+
*
|
|
1554
|
+
* @tags Groupless
|
|
1555
|
+
* @name PostGrouplessTransfer
|
|
1556
|
+
* @summary Build unsigned transfer transactions from a groupless address
|
|
1557
|
+
* @request POST:/groupless/transfer
|
|
1558
|
+
*/
|
|
1559
|
+
postGrouplessTransfer: (data, params = {}) => this.request({
|
|
1560
|
+
path: `/groupless/transfer`,
|
|
1561
|
+
method: 'POST',
|
|
1562
|
+
body: data,
|
|
1563
|
+
type: ContentType.Json,
|
|
1564
|
+
format: 'json',
|
|
1565
|
+
...params
|
|
1566
|
+
}).then(utils_1.convertHttpResponse),
|
|
1567
|
+
/**
|
|
1568
|
+
* No description
|
|
1569
|
+
*
|
|
1570
|
+
* @tags Groupless
|
|
1571
|
+
* @name PostGrouplessExecuteScript
|
|
1572
|
+
* @summary Build an unsigned execute script transaction from a groupless address
|
|
1573
|
+
* @request POST:/groupless/execute-script
|
|
1574
|
+
*/
|
|
1575
|
+
postGrouplessExecuteScript: (data, params = {}) => this.request({
|
|
1576
|
+
path: `/groupless/execute-script`,
|
|
1577
|
+
method: 'POST',
|
|
1578
|
+
body: data,
|
|
1579
|
+
type: ContentType.Json,
|
|
1580
|
+
format: 'json',
|
|
1581
|
+
...params
|
|
1582
|
+
}).then(utils_1.convertHttpResponse),
|
|
1583
|
+
/**
|
|
1584
|
+
* No description
|
|
1585
|
+
*
|
|
1586
|
+
* @tags Groupless
|
|
1587
|
+
* @name PostGrouplessDeployContract
|
|
1588
|
+
* @summary Build an unsigned deploy contract transaction from a groupless address
|
|
1589
|
+
* @request POST:/groupless/deploy-contract
|
|
1590
|
+
*/
|
|
1591
|
+
postGrouplessDeployContract: (data, params = {}) => this.request({
|
|
1592
|
+
path: `/groupless/deploy-contract`,
|
|
1593
|
+
method: 'POST',
|
|
1594
|
+
body: data,
|
|
1595
|
+
type: ContentType.Json,
|
|
1596
|
+
format: 'json',
|
|
1597
|
+
...params
|
|
1598
|
+
}).then(utils_1.convertHttpResponse)
|
|
1599
|
+
};
|
|
1550
1600
|
}
|
|
1551
1601
|
}
|
|
1552
1602
|
exports.Api = Api;
|
|
@@ -14,6 +14,7 @@ interface NodeProviderApis {
|
|
|
14
14
|
utils: NodeApi<string>['utils'];
|
|
15
15
|
miners: NodeApi<string>['miners'];
|
|
16
16
|
events: NodeApi<string>['events'];
|
|
17
|
+
groupless: NodeApi<string>['groupless'];
|
|
17
18
|
}
|
|
18
19
|
export declare class NodeProvider implements NodeProviderApis {
|
|
19
20
|
readonly wallets: NodeApi<string>['wallets'];
|
|
@@ -27,6 +28,7 @@ export declare class NodeProvider implements NodeProviderApis {
|
|
|
27
28
|
readonly utils: NodeApi<string>['utils'];
|
|
28
29
|
readonly miners: NodeApi<string>['miners'];
|
|
29
30
|
readonly events: NodeApi<string>['events'];
|
|
31
|
+
readonly groupless: NodeApi<string>['groupless'];
|
|
30
32
|
constructor(baseUrl: string, apiKey?: string, customFetch?: typeof fetch);
|
|
31
33
|
constructor(provider: NodeProvider);
|
|
32
34
|
constructor(handler: ApiRequestHandler);
|
|
@@ -185,6 +185,7 @@ class NodeProvider {
|
|
|
185
185
|
this.utils = { ...nodeApi.utils };
|
|
186
186
|
this.miners = { ...nodeApi.miners };
|
|
187
187
|
this.events = { ...nodeApi.events };
|
|
188
|
+
this.groupless = { ...nodeApi.groupless };
|
|
188
189
|
(0, types_1.requestWithLog)(this);
|
|
189
190
|
}
|
|
190
191
|
// This can prevent the proxied node provider from being modified
|
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' });
|