@alephium/web3 1.7.2 → 1.7.4
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 +2 -1
- package/dist/src/address/address.js +27 -19
- package/dist/src/api/api-alephium.d.ts +114 -1
- package/dist/src/api/api-alephium.js +30 -1
- package/dist/src/api/api-explorer.d.ts +55 -0
- package/dist/src/api/api-explorer.js +28 -0
- package/dist/src/contract/contract.d.ts +3 -1
- package/dist/src/contract/contract.js +4 -2
- package/dist/src/signer/tx-builder.d.ts +1 -1
- package/dist/src/signer/tx-builder.js +13 -8
- package/dist/src/transaction/utils.d.ts +2 -0
- package/dist/src/transaction/utils.js +23 -1
- package/dist/src/utils/utils.d.ts +4 -0
- package/dist/src/utils/utils.js +9 -1
- package/package.json +4 -4
- package/src/address/address.ts +24 -18
- package/src/api/api-alephium.ts +144 -1
- package/src/api/api-explorer.ts +79 -0
- package/src/contract/contract.ts +5 -2
- package/src/signer/tx-builder.ts +14 -9
- package/src/transaction/utils.ts +26 -0
- package/src/utils/utils.ts +16 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KeyType } from '../signer';
|
|
2
|
+
import { LockupScript } from '../codec/lockup-script-codec';
|
|
2
3
|
export declare enum AddressType {
|
|
3
4
|
P2PKH = 0,
|
|
4
5
|
P2MPKH = 1,
|
|
@@ -20,4 +21,4 @@ export declare function addressFromContractId(contractId: string): string;
|
|
|
20
21
|
export declare function addressFromTokenId(tokenId: string): string;
|
|
21
22
|
export declare function contractIdFromTx(txId: string, outputIndex: number): string;
|
|
22
23
|
export declare function subContractId(parentContractId: string, pathInHex: string, group: number): string;
|
|
23
|
-
export declare function
|
|
24
|
+
export declare function groupOfLockupScript(lockupScript: LockupScript): number;
|
|
@@ -20,16 +20,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
23
|
+
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;
|
|
24
24
|
const elliptic_1 = require("elliptic");
|
|
25
25
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
26
26
|
const constants_1 = require("../constants");
|
|
27
27
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
28
28
|
const bs58_1 = __importDefault(require("../utils/bs58"));
|
|
29
|
-
const djb2_1 = __importDefault(require("../utils/djb2"));
|
|
30
29
|
const utils_1 = require("../utils");
|
|
31
30
|
const lockup_script_codec_1 = require("../codec/lockup-script-codec");
|
|
32
31
|
const codec_1 = require("../codec");
|
|
32
|
+
const djb2_1 = __importDefault(require("../utils/djb2"));
|
|
33
33
|
const ec = new elliptic_1.ec('secp256k1');
|
|
34
34
|
const PublicKeyHashSize = 32;
|
|
35
35
|
var AddressType;
|
|
@@ -120,23 +120,17 @@ function groupOfAddress(address) {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
exports.groupOfAddress = groupOfAddress;
|
|
123
|
-
function groupOfAddressBytes(bytes) {
|
|
124
|
-
const hint = (0, djb2_1.default)(bytes) | 1;
|
|
125
|
-
const hash = xorByte(hint);
|
|
126
|
-
const group = hash % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
127
|
-
return group;
|
|
128
|
-
}
|
|
129
123
|
// Pay to public key hash address
|
|
130
124
|
function groupOfP2pkhAddress(address) {
|
|
131
|
-
return
|
|
125
|
+
return groupFromBytesForAssetAddress(address);
|
|
132
126
|
}
|
|
133
127
|
// Pay to multiple public key hash address
|
|
134
128
|
function groupOfP2mpkhAddress(address) {
|
|
135
|
-
return
|
|
129
|
+
return groupFromBytesForAssetAddress(address.slice(1, 33));
|
|
136
130
|
}
|
|
137
131
|
// Pay to script hash address
|
|
138
132
|
function groupOfP2shAddress(address) {
|
|
139
|
-
return
|
|
133
|
+
return groupFromBytesForAssetAddress(address);
|
|
140
134
|
}
|
|
141
135
|
function contractIdFromAddress(address) {
|
|
142
136
|
return idFromAddress(address);
|
|
@@ -228,11 +222,25 @@ function subContractId(parentContractId, pathInHex, group) {
|
|
|
228
222
|
return (0, utils_1.binToHex)(bytes);
|
|
229
223
|
}
|
|
230
224
|
exports.subContractId = subContractId;
|
|
231
|
-
function
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
225
|
+
function groupOfLockupScript(lockupScript) {
|
|
226
|
+
if (lockupScript.kind === 'P2PKH') {
|
|
227
|
+
return groupFromBytesForAssetAddress(lockupScript.value);
|
|
228
|
+
}
|
|
229
|
+
else if (lockupScript.kind === 'P2MPKH') {
|
|
230
|
+
return groupFromBytesForAssetAddress(lockupScript.value.publicKeyHashes[0]);
|
|
231
|
+
}
|
|
232
|
+
else if (lockupScript.kind === 'P2SH') {
|
|
233
|
+
return groupFromBytesForAssetAddress(lockupScript.value);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// P2C
|
|
237
|
+
const contractId = lockupScript.value;
|
|
238
|
+
return contractId[`${contractId.length - 1}`];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.groupOfLockupScript = groupOfLockupScript;
|
|
242
|
+
function groupFromBytesForAssetAddress(bytes) {
|
|
243
|
+
const hint = (0, djb2_1.default)(bytes) | 1;
|
|
244
|
+
const hash = (0, utils_1.xorByte)(hint);
|
|
245
|
+
return hash % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
246
|
+
}
|
|
@@ -818,6 +818,90 @@ export interface RevealMnemonic {
|
|
|
818
818
|
export interface RevealMnemonicResult {
|
|
819
819
|
mnemonic: string;
|
|
820
820
|
}
|
|
821
|
+
/** RichAssetInput */
|
|
822
|
+
export interface RichAssetInput {
|
|
823
|
+
/** @format int32 */
|
|
824
|
+
hint: number;
|
|
825
|
+
/** @format 32-byte-hash */
|
|
826
|
+
key: string;
|
|
827
|
+
/** @format hex-string */
|
|
828
|
+
unlockScript: string;
|
|
829
|
+
/** @format uint256 */
|
|
830
|
+
attoAlphAmount: string;
|
|
831
|
+
/** @format address */
|
|
832
|
+
address: string;
|
|
833
|
+
tokens: Token[];
|
|
834
|
+
}
|
|
835
|
+
/** RichBlockAndEvents */
|
|
836
|
+
export interface RichBlockAndEvents {
|
|
837
|
+
block: RichBlockEntry;
|
|
838
|
+
events: ContractEventByBlockHash[];
|
|
839
|
+
}
|
|
840
|
+
/** RichBlockEntry */
|
|
841
|
+
export interface RichBlockEntry {
|
|
842
|
+
/** @format block-hash */
|
|
843
|
+
hash: string;
|
|
844
|
+
/** @format int64 */
|
|
845
|
+
timestamp: number;
|
|
846
|
+
/** @format int32 */
|
|
847
|
+
chainFrom: number;
|
|
848
|
+
/** @format int32 */
|
|
849
|
+
chainTo: number;
|
|
850
|
+
/** @format int32 */
|
|
851
|
+
height: number;
|
|
852
|
+
deps: string[];
|
|
853
|
+
transactions: RichTransaction[];
|
|
854
|
+
/** @format hex-string */
|
|
855
|
+
nonce: string;
|
|
856
|
+
version: number;
|
|
857
|
+
/** @format 32-byte-hash */
|
|
858
|
+
depStateHash: string;
|
|
859
|
+
/** @format 32-byte-hash */
|
|
860
|
+
txsHash: string;
|
|
861
|
+
/** @format hex-string */
|
|
862
|
+
target: string;
|
|
863
|
+
ghostUncles: GhostUncleBlockEntry[];
|
|
864
|
+
}
|
|
865
|
+
/** RichBlocksAndEventsPerTimeStampRange */
|
|
866
|
+
export interface RichBlocksAndEventsPerTimeStampRange {
|
|
867
|
+
blocksAndEvents: RichBlockAndEvents[][];
|
|
868
|
+
}
|
|
869
|
+
/** RichContractInput */
|
|
870
|
+
export interface RichContractInput {
|
|
871
|
+
/** @format int32 */
|
|
872
|
+
hint: number;
|
|
873
|
+
/** @format 32-byte-hash */
|
|
874
|
+
key: string;
|
|
875
|
+
/** @format uint256 */
|
|
876
|
+
attoAlphAmount: string;
|
|
877
|
+
/** @format address */
|
|
878
|
+
address: string;
|
|
879
|
+
tokens: Token[];
|
|
880
|
+
}
|
|
881
|
+
/** RichTransaction */
|
|
882
|
+
export interface RichTransaction {
|
|
883
|
+
unsigned: RichUnsignedTx;
|
|
884
|
+
scriptExecutionOk: boolean;
|
|
885
|
+
contractInputs: RichContractInput[];
|
|
886
|
+
generatedOutputs: Output[];
|
|
887
|
+
inputSignatures: string[];
|
|
888
|
+
scriptSignatures: string[];
|
|
889
|
+
}
|
|
890
|
+
/** RichUnsignedTx */
|
|
891
|
+
export interface RichUnsignedTx {
|
|
892
|
+
/** @format 32-byte-hash */
|
|
893
|
+
txId: string;
|
|
894
|
+
version: number;
|
|
895
|
+
networkId: number;
|
|
896
|
+
/** @format script */
|
|
897
|
+
scriptOpt?: string;
|
|
898
|
+
/** @format int32 */
|
|
899
|
+
gasAmount: number;
|
|
900
|
+
/** @format uint256 */
|
|
901
|
+
gasPrice: string;
|
|
902
|
+
inputs: RichAssetInput[];
|
|
903
|
+
fixedOutputs: FixedAssetOutput[];
|
|
904
|
+
}
|
|
821
905
|
/** Script */
|
|
822
906
|
export interface Script {
|
|
823
907
|
code: string;
|
|
@@ -1205,7 +1289,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
1205
1289
|
}
|
|
1206
1290
|
/**
|
|
1207
1291
|
* @title Alephium API
|
|
1208
|
-
* @version 3.
|
|
1292
|
+
* @version 3.7.0
|
|
1209
1293
|
* @baseUrl ../
|
|
1210
1294
|
*/
|
|
1211
1295
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -1562,6 +1646,26 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1562
1646
|
*/
|
|
1563
1647
|
toTs?: number;
|
|
1564
1648
|
}, params?: RequestParams) => Promise<BlocksAndEventsPerTimeStampRange>;
|
|
1649
|
+
/**
|
|
1650
|
+
* No description
|
|
1651
|
+
*
|
|
1652
|
+
* @tags Blockflow
|
|
1653
|
+
* @name GetBlockflowRichBlocks
|
|
1654
|
+
* @summary Given a time interval, list blocks containing events and transactions with enriched input information when node indexes are enabled.
|
|
1655
|
+
* @request GET:/blockflow/rich-blocks
|
|
1656
|
+
*/
|
|
1657
|
+
getBlockflowRichBlocks: (query: {
|
|
1658
|
+
/**
|
|
1659
|
+
* @format int64
|
|
1660
|
+
* @min 0
|
|
1661
|
+
*/
|
|
1662
|
+
fromTs: number;
|
|
1663
|
+
/**
|
|
1664
|
+
* @format int64
|
|
1665
|
+
* @min 0
|
|
1666
|
+
*/
|
|
1667
|
+
toTs?: number;
|
|
1668
|
+
}, params?: RequestParams) => Promise<RichBlocksAndEventsPerTimeStampRange>;
|
|
1565
1669
|
/**
|
|
1566
1670
|
* No description
|
|
1567
1671
|
*
|
|
@@ -1589,6 +1693,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1589
1693
|
* @request GET:/blockflow/blocks-with-events/{block_hash}
|
|
1590
1694
|
*/
|
|
1591
1695
|
getBlockflowBlocksWithEventsBlockHash: (blockHash: string, params?: RequestParams) => Promise<BlockAndEvents>;
|
|
1696
|
+
/**
|
|
1697
|
+
* No description
|
|
1698
|
+
*
|
|
1699
|
+
* @tags Blockflow
|
|
1700
|
+
* @name GetBlockflowRichBlocksBlockHash
|
|
1701
|
+
* @summary Get a block containing events and transactions with enriched input information when node indexes are enabled.
|
|
1702
|
+
* @request GET:/blockflow/rich-blocks/{block_hash}
|
|
1703
|
+
*/
|
|
1704
|
+
getBlockflowRichBlocksBlockHash: (blockHash: string, params?: RequestParams) => Promise<RichBlockAndEvents>;
|
|
1592
1705
|
/**
|
|
1593
1706
|
* No description
|
|
1594
1707
|
*
|
|
@@ -151,7 +151,7 @@ class HttpClient {
|
|
|
151
151
|
exports.HttpClient = HttpClient;
|
|
152
152
|
/**
|
|
153
153
|
* @title Alephium API
|
|
154
|
-
* @version 3.
|
|
154
|
+
* @version 3.7.0
|
|
155
155
|
* @baseUrl ../
|
|
156
156
|
*/
|
|
157
157
|
class Api extends HttpClient {
|
|
@@ -661,6 +661,21 @@ class Api extends HttpClient {
|
|
|
661
661
|
format: 'json',
|
|
662
662
|
...params
|
|
663
663
|
}).then(utils_1.convertHttpResponse),
|
|
664
|
+
/**
|
|
665
|
+
* No description
|
|
666
|
+
*
|
|
667
|
+
* @tags Blockflow
|
|
668
|
+
* @name GetBlockflowRichBlocks
|
|
669
|
+
* @summary Given a time interval, list blocks containing events and transactions with enriched input information when node indexes are enabled.
|
|
670
|
+
* @request GET:/blockflow/rich-blocks
|
|
671
|
+
*/
|
|
672
|
+
getBlockflowRichBlocks: (query, params = {}) => this.request({
|
|
673
|
+
path: `/blockflow/rich-blocks`,
|
|
674
|
+
method: 'GET',
|
|
675
|
+
query: query,
|
|
676
|
+
format: 'json',
|
|
677
|
+
...params
|
|
678
|
+
}).then(utils_1.convertHttpResponse),
|
|
664
679
|
/**
|
|
665
680
|
* No description
|
|
666
681
|
*
|
|
@@ -703,6 +718,20 @@ class Api extends HttpClient {
|
|
|
703
718
|
format: 'json',
|
|
704
719
|
...params
|
|
705
720
|
}).then(utils_1.convertHttpResponse),
|
|
721
|
+
/**
|
|
722
|
+
* No description
|
|
723
|
+
*
|
|
724
|
+
* @tags Blockflow
|
|
725
|
+
* @name GetBlockflowRichBlocksBlockHash
|
|
726
|
+
* @summary Get a block containing events and transactions with enriched input information when node indexes are enabled.
|
|
727
|
+
* @request GET:/blockflow/rich-blocks/{block_hash}
|
|
728
|
+
*/
|
|
729
|
+
getBlockflowRichBlocksBlockHash: (blockHash, params = {}) => this.request({
|
|
730
|
+
path: `/blockflow/rich-blocks/${blockHash}`,
|
|
731
|
+
method: 'GET',
|
|
732
|
+
format: 'json',
|
|
733
|
+
...params
|
|
734
|
+
}).then(utils_1.convertHttpResponse),
|
|
706
735
|
/**
|
|
707
736
|
* No description
|
|
708
737
|
*
|
|
@@ -162,6 +162,7 @@ export interface AssetOutput {
|
|
|
162
162
|
}
|
|
163
163
|
/** NFT */
|
|
164
164
|
export interface NFT {
|
|
165
|
+
id: string;
|
|
165
166
|
type: string;
|
|
166
167
|
}
|
|
167
168
|
/** AcceptedTransaction */
|
|
@@ -187,6 +188,13 @@ export interface AcceptedTransaction {
|
|
|
187
188
|
/** @format int64 */
|
|
188
189
|
timestamp: number;
|
|
189
190
|
}
|
|
191
|
+
/** HolderInfo */
|
|
192
|
+
export interface HolderInfo {
|
|
193
|
+
/** @format address */
|
|
194
|
+
address: string;
|
|
195
|
+
/** @format uint256 */
|
|
196
|
+
balance: string;
|
|
197
|
+
}
|
|
190
198
|
/** TokenSupply */
|
|
191
199
|
export interface TokenSupply {
|
|
192
200
|
/** @format uint256 */
|
|
@@ -278,6 +286,8 @@ export declare enum TokenStdInterfaceId {
|
|
|
278
286
|
export interface ExplorerInfo {
|
|
279
287
|
releaseVersion: string;
|
|
280
288
|
commit: string;
|
|
289
|
+
/** @format int64 */
|
|
290
|
+
lastHoldersUpdate: number;
|
|
281
291
|
/** @format int32 */
|
|
282
292
|
migrationsVersion: number;
|
|
283
293
|
/** @format int64 */
|
|
@@ -323,6 +333,7 @@ export interface Transaction {
|
|
|
323
333
|
}
|
|
324
334
|
/** FungibleToken */
|
|
325
335
|
export interface FungibleToken {
|
|
336
|
+
id: string;
|
|
326
337
|
type: string;
|
|
327
338
|
}
|
|
328
339
|
/** GhostUncle */
|
|
@@ -1045,6 +1056,28 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1045
1056
|
*/
|
|
1046
1057
|
'interface-id'?: TokenStdInterfaceId | string;
|
|
1047
1058
|
}, params?: RequestParams) => Promise<TokenInfo[]>;
|
|
1059
|
+
/**
|
|
1060
|
+
* @description Get a sorted list of top addresses by {token_id} balance. Updates once per day.
|
|
1061
|
+
*
|
|
1062
|
+
* @tags Tokens
|
|
1063
|
+
* @name GetTokensHoldersTokenTokenId
|
|
1064
|
+
* @request GET:/tokens/holders/token/{token_id}
|
|
1065
|
+
*/
|
|
1066
|
+
getTokensHoldersTokenTokenId: (tokenId: string, query?: {
|
|
1067
|
+
/**
|
|
1068
|
+
* Page number
|
|
1069
|
+
* @format int32
|
|
1070
|
+
* @min 1
|
|
1071
|
+
*/
|
|
1072
|
+
page?: number;
|
|
1073
|
+
/**
|
|
1074
|
+
* Number of items per page
|
|
1075
|
+
* @format int32
|
|
1076
|
+
* @min 0
|
|
1077
|
+
* @max 100
|
|
1078
|
+
*/
|
|
1079
|
+
limit?: number;
|
|
1080
|
+
}, params?: RequestParams) => Promise<HolderInfo[]>;
|
|
1048
1081
|
/**
|
|
1049
1082
|
* @description List token transactions
|
|
1050
1083
|
*
|
|
@@ -1097,6 +1130,28 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1097
1130
|
*/
|
|
1098
1131
|
limit?: number;
|
|
1099
1132
|
}, params?: RequestParams) => Promise<string[]>;
|
|
1133
|
+
/**
|
|
1134
|
+
* @description Get a sorted list of top addresses by ALPH balance. Updates once per day.
|
|
1135
|
+
*
|
|
1136
|
+
* @tags Tokens
|
|
1137
|
+
* @name GetTokensHoldersAlph
|
|
1138
|
+
* @request GET:/tokens/holders/alph
|
|
1139
|
+
*/
|
|
1140
|
+
getTokensHoldersAlph: (query?: {
|
|
1141
|
+
/**
|
|
1142
|
+
* Page number
|
|
1143
|
+
* @format int32
|
|
1144
|
+
* @min 1
|
|
1145
|
+
*/
|
|
1146
|
+
page?: number;
|
|
1147
|
+
/**
|
|
1148
|
+
* Number of items per page
|
|
1149
|
+
* @format int32
|
|
1150
|
+
* @min 0
|
|
1151
|
+
* @max 100
|
|
1152
|
+
*/
|
|
1153
|
+
limit?: number;
|
|
1154
|
+
}, params?: RequestParams) => Promise<HolderInfo[]>;
|
|
1100
1155
|
/**
|
|
1101
1156
|
* @description Return metadata for the given nft tokens, if metadata doesn't exist or token isn't a nft, it won't be in the output list
|
|
1102
1157
|
*
|
|
@@ -680,6 +680,20 @@ class Api extends HttpClient {
|
|
|
680
680
|
format: 'json',
|
|
681
681
|
...params
|
|
682
682
|
}).then(utils_1.convertHttpResponse),
|
|
683
|
+
/**
|
|
684
|
+
* @description Get a sorted list of top addresses by {token_id} balance. Updates once per day.
|
|
685
|
+
*
|
|
686
|
+
* @tags Tokens
|
|
687
|
+
* @name GetTokensHoldersTokenTokenId
|
|
688
|
+
* @request GET:/tokens/holders/token/{token_id}
|
|
689
|
+
*/
|
|
690
|
+
getTokensHoldersTokenTokenId: (tokenId, query, params = {}) => this.request({
|
|
691
|
+
path: `/tokens/holders/token/${tokenId}`,
|
|
692
|
+
method: 'GET',
|
|
693
|
+
query: query,
|
|
694
|
+
format: 'json',
|
|
695
|
+
...params
|
|
696
|
+
}).then(utils_1.convertHttpResponse),
|
|
683
697
|
/**
|
|
684
698
|
* @description List token transactions
|
|
685
699
|
*
|
|
@@ -723,6 +737,20 @@ class Api extends HttpClient {
|
|
|
723
737
|
format: 'json',
|
|
724
738
|
...params
|
|
725
739
|
}).then(utils_1.convertHttpResponse),
|
|
740
|
+
/**
|
|
741
|
+
* @description Get a sorted list of top addresses by ALPH balance. Updates once per day.
|
|
742
|
+
*
|
|
743
|
+
* @tags Tokens
|
|
744
|
+
* @name GetTokensHoldersAlph
|
|
745
|
+
* @request GET:/tokens/holders/alph
|
|
746
|
+
*/
|
|
747
|
+
getTokensHoldersAlph: (query, params = {}) => this.request({
|
|
748
|
+
path: `/tokens/holders/alph`,
|
|
749
|
+
method: 'GET',
|
|
750
|
+
query: query,
|
|
751
|
+
format: 'json',
|
|
752
|
+
...params
|
|
753
|
+
}).then(utils_1.convertHttpResponse),
|
|
726
754
|
/**
|
|
727
755
|
* @description Return metadata for the given nft tokens, if metadata doesn't exist or token isn't a nft, it won't be in the output list
|
|
728
756
|
*
|
|
@@ -303,7 +303,9 @@ export declare function subscribeContractEvent<F extends Fields, M extends Contr
|
|
|
303
303
|
export declare function subscribeContractEvents(contract: Contract, instance: ContractInstance, options: EventSubscribeOptions<ContractEvent<any>>, fromCount?: number): EventSubscription;
|
|
304
304
|
export declare function callMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<CallContractParams<A>, 'args'>, getContractByCodeHash: (codeHash: string) => Contract): Promise<CallContractResult<R>>;
|
|
305
305
|
export declare function signExecuteMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<SignExecuteContractMethodParams<A>, 'args'>): Promise<SignExecuteScriptTxResult>;
|
|
306
|
-
|
|
306
|
+
type Calls = Record<string, Optional<CallContractParams<any>, 'args'>>;
|
|
307
|
+
export declare function multicallMethods<I extends ContractInstance, F extends Fields>(contract: ContractFactory<I, F>, instance: ContractInstance, _callss: Calls | Calls[], getContractByCodeHash: (codeHash: string) => Contract): Promise<Record<string, CallContractResult<any>>[] | Record<string, CallContractResult<any>>>;
|
|
307
308
|
export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
|
|
308
309
|
export declare const getContractIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
|
|
309
310
|
export declare const getTokenIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
|
|
311
|
+
export {};
|
|
@@ -1328,7 +1328,8 @@ function toFieldsSig(contractName, functionSig) {
|
|
|
1328
1328
|
isMutable: [false].concat(functionSig.paramIsMutable)
|
|
1329
1329
|
};
|
|
1330
1330
|
}
|
|
1331
|
-
async function multicallMethods(contract, instance,
|
|
1331
|
+
async function multicallMethods(contract, instance, _callss, getContractByCodeHash) {
|
|
1332
|
+
const callss = Array.isArray(_callss) ? _callss : [_callss];
|
|
1332
1333
|
const callEntries = callss.map((calls) => Object.entries(calls));
|
|
1333
1334
|
const callsParams = callEntries.map((entries) => {
|
|
1334
1335
|
return entries.map((entry) => {
|
|
@@ -1340,7 +1341,7 @@ async function multicallMethods(contract, instance, callss, getContractByCodeHas
|
|
|
1340
1341
|
});
|
|
1341
1342
|
const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsMulticallContract({ calls: callsParams.flat() });
|
|
1342
1343
|
let callResultIndex = 0;
|
|
1343
|
-
|
|
1344
|
+
const results = callsParams.map((calls, index0) => {
|
|
1344
1345
|
const callsResult = {};
|
|
1345
1346
|
const entries = callEntries[`${index0}`];
|
|
1346
1347
|
calls.forEach((call, index1) => {
|
|
@@ -1352,6 +1353,7 @@ async function multicallMethods(contract, instance, callss, getContractByCodeHas
|
|
|
1352
1353
|
});
|
|
1353
1354
|
return callsResult;
|
|
1354
1355
|
});
|
|
1356
|
+
return Array.isArray(_callss) ? results : results[0];
|
|
1355
1357
|
}
|
|
1356
1358
|
exports.multicallMethods = multicallMethods;
|
|
1357
1359
|
async function getContractEventsCurrentCount(contractAddress) {
|
|
@@ -8,5 +8,5 @@ export declare abstract class TransactionBuilder {
|
|
|
8
8
|
buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<Omit<SignTransferTxResult, 'signature'>>;
|
|
9
9
|
buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<Omit<SignDeployContractTxResult, 'signature'>>;
|
|
10
10
|
buildExecuteScriptTx(params: SignExecuteScriptTxParams, publicKey: string): Promise<Omit<SignExecuteScriptTxResult, 'signature'>>;
|
|
11
|
-
buildUnsignedTx(params: SignUnsignedTxParams):
|
|
11
|
+
buildUnsignedTx(params: SignUnsignedTxParams): Omit<SignUnsignedTxResult, 'signature'>;
|
|
12
12
|
}
|
|
@@ -22,6 +22,9 @@ const utils_1 = require("../utils");
|
|
|
22
22
|
const api_1 = require("../api");
|
|
23
23
|
const address_1 = require("../address");
|
|
24
24
|
const signer_1 = require("./signer");
|
|
25
|
+
const codec_1 = require("../codec");
|
|
26
|
+
const transaction_1 = require("../transaction");
|
|
27
|
+
const hash_1 = require("../codec/hash");
|
|
25
28
|
class TransactionBuilder {
|
|
26
29
|
static from(param0, param1, customFetch) {
|
|
27
30
|
const nodeProvider = typeof param0 === 'string' ? new api_1.NodeProvider(param0, param1, customFetch) : param0;
|
|
@@ -80,16 +83,18 @@ class TransactionBuilder {
|
|
|
80
83
|
const response = await this.nodeProvider.contracts.postContractsUnsignedTxExecuteScript(data);
|
|
81
84
|
return { ...response, groupIndex: response.fromGroup, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
|
|
82
85
|
}
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const decoded =
|
|
86
|
+
buildUnsignedTx(params) {
|
|
87
|
+
const unsignedTxBin = (0, utils_1.hexToBinUnsafe)(params.unsignedTx);
|
|
88
|
+
const decoded = codec_1.unsignedTxCodec.decode(unsignedTxBin);
|
|
89
|
+
const txId = (0, utils_1.binToHex)((0, hash_1.blakeHash)(unsignedTxBin));
|
|
90
|
+
const [fromGroup, toGroup] = (0, transaction_1.groupIndexOfTransaction)(decoded);
|
|
86
91
|
return {
|
|
87
|
-
fromGroup:
|
|
88
|
-
toGroup:
|
|
92
|
+
fromGroup: fromGroup,
|
|
93
|
+
toGroup: toGroup,
|
|
89
94
|
unsignedTx: params.unsignedTx,
|
|
90
|
-
txId:
|
|
91
|
-
gasAmount: decoded.
|
|
92
|
-
gasPrice:
|
|
95
|
+
txId: txId,
|
|
96
|
+
gasAmount: decoded.gasAmount,
|
|
97
|
+
gasPrice: decoded.gasPrice
|
|
93
98
|
};
|
|
94
99
|
}
|
|
95
100
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { node } from '../api';
|
|
2
|
+
import { UnsignedTx } from '../codec';
|
|
2
3
|
export declare function waitForTxConfirmation(txId: string, confirmations: number, requestInterval: number): Promise<node.Confirmed>;
|
|
4
|
+
export declare function groupIndexOfTransaction(unsignedTx: UnsignedTx): [number, number];
|
|
@@ -17,8 +17,11 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.waitForTxConfirmation = void 0;
|
|
20
|
+
exports.groupIndexOfTransaction = exports.waitForTxConfirmation = void 0;
|
|
21
|
+
const address_1 = require("../address");
|
|
22
|
+
const constants_1 = require("../constants");
|
|
21
23
|
const global_1 = require("../global");
|
|
24
|
+
const utils_1 = require("../utils");
|
|
22
25
|
function isConfirmed(txStatus) {
|
|
23
26
|
return txStatus.type === 'Confirmed';
|
|
24
27
|
}
|
|
@@ -32,3 +35,22 @@ async function waitForTxConfirmation(txId, confirmations, requestInterval) {
|
|
|
32
35
|
return waitForTxConfirmation(txId, confirmations, requestInterval);
|
|
33
36
|
}
|
|
34
37
|
exports.waitForTxConfirmation = waitForTxConfirmation;
|
|
38
|
+
function groupIndexOfTransaction(unsignedTx) {
|
|
39
|
+
if (unsignedTx.inputs.length === 0)
|
|
40
|
+
throw new Error('Empty inputs for unsignedTx');
|
|
41
|
+
const fromGroup = groupFromHint(unsignedTx.inputs[0].hint);
|
|
42
|
+
let toGroup = fromGroup;
|
|
43
|
+
for (const output of unsignedTx.fixedOutputs) {
|
|
44
|
+
const outputGroup = (0, address_1.groupOfLockupScript)(output.lockupScript);
|
|
45
|
+
if (outputGroup !== fromGroup) {
|
|
46
|
+
toGroup = outputGroup;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return [fromGroup, toGroup];
|
|
51
|
+
}
|
|
52
|
+
exports.groupIndexOfTransaction = groupIndexOfTransaction;
|
|
53
|
+
function groupFromHint(hint) {
|
|
54
|
+
const hash = (0, utils_1.xorByte)(hint);
|
|
55
|
+
return hash % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
56
|
+
}
|
|
@@ -24,6 +24,7 @@ export declare function isDevnet(networkId?: number): boolean;
|
|
|
24
24
|
export declare function targetToDifficulty(compactedTarget: HexString): bigint;
|
|
25
25
|
export declare function difficultyToTarget(diff: bigint): HexString;
|
|
26
26
|
export declare function concatBytes(arrays: Uint8Array[]): Uint8Array;
|
|
27
|
+
export declare function xorByte(intValue: number): number;
|
|
27
28
|
type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
28
29
|
export type Eq<X, Y> = _Eq<{
|
|
29
30
|
[P in keyof X]: X[P];
|
|
@@ -32,4 +33,7 @@ export type Eq<X, Y> = _Eq<{
|
|
|
32
33
|
}>;
|
|
33
34
|
export declare function assertType<T extends true>(): void;
|
|
34
35
|
export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
36
|
+
export type Narrow<type> = (unknown extends type ? unknown : never) | (type extends Function ? type : never) | (type extends bigint | boolean | number | string ? type : never) | (type extends [] ? [] : never) | {
|
|
37
|
+
[K in keyof type]: Narrow<type[K]>;
|
|
38
|
+
};
|
|
35
39
|
export {};
|
package/dist/src/utils/utils.js
CHANGED
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.assertType = exports.concatBytes = exports.difficultyToTarget = exports.targetToDifficulty = exports.isDevnet = exports.sleep = exports.hexToString = exports.stringToHex = exports.blockChainIndex = exports.binToHex = exports.hexToBinUnsafe = exports.toNonNegativeBigInt = exports.isHexString = exports.signatureDecode = exports.encodeHexSignature = exports.encodeSignature = exports.networkIds = void 0;
|
|
23
|
+
exports.assertType = exports.xorByte = exports.concatBytes = exports.difficultyToTarget = exports.targetToDifficulty = exports.isDevnet = exports.sleep = exports.hexToString = exports.stringToHex = exports.blockChainIndex = exports.binToHex = exports.hexToBinUnsafe = exports.toNonNegativeBigInt = exports.isHexString = exports.signatureDecode = exports.encodeHexSignature = exports.encodeSignature = exports.networkIds = void 0;
|
|
24
24
|
const elliptic_1 = require("elliptic");
|
|
25
25
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
26
26
|
const constants_1 = require("../constants");
|
|
@@ -153,6 +153,14 @@ function concatBytes(arrays) {
|
|
|
153
153
|
return result;
|
|
154
154
|
}
|
|
155
155
|
exports.concatBytes = concatBytes;
|
|
156
|
+
function xorByte(intValue) {
|
|
157
|
+
const byte0 = (intValue >> 24) & 0xff;
|
|
158
|
+
const byte1 = (intValue >> 16) & 0xff;
|
|
159
|
+
const byte2 = (intValue >> 8) & 0xff;
|
|
160
|
+
const byte3 = intValue & 0xff;
|
|
161
|
+
return (byte0 ^ byte1 ^ byte2 ^ byte3) & 0xff;
|
|
162
|
+
}
|
|
163
|
+
exports.xorByte = xorByte;
|
|
156
164
|
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
|
|
157
165
|
function assertType() { }
|
|
158
166
|
exports.assertType = assertType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"author": "Alephium dev <dev@alephium.org>",
|
|
35
35
|
"config": {
|
|
36
|
-
"alephium_version": "3.
|
|
37
|
-
"explorer_backend_version": "2.
|
|
36
|
+
"alephium_version": "3.7.0",
|
|
37
|
+
"explorer_backend_version": "2.2.3"
|
|
38
38
|
},
|
|
39
39
|
"type": "commonjs",
|
|
40
40
|
"dependencies": {
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"ts-node": "^10.9.1",
|
|
84
84
|
"tslib": "^2.5.0",
|
|
85
85
|
"typescript": "^4.9.5",
|
|
86
|
-
"webpack": "^5.
|
|
86
|
+
"webpack": "^5.94.0",
|
|
87
87
|
"webpack-cli": "^4.10.0"
|
|
88
88
|
},
|
|
89
89
|
"engines": {
|