@alephium/web3 0.8.2-test.3 → 0.9.0-rc.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/LICENSE +165 -0
- package/package.json +37 -36
- package/src/api/api-alephium.ts +2 -1
- package/src/api/node-provider.ts +41 -25
- package/src/api/types.ts +10 -15
- package/src/contract/contract.ts +63 -40
- package/src/index.ts +1 -0
- package/{dist/scripts/header.js → src/token/index.ts} +2 -1
- package/{dist/src/utils/djb2.js → src/token/nft.ts} +16 -9
- package/std/fungible_token_interface.ral +1 -0
- package/std/nft_collection_interface.ral +24 -3
- package/std/nft_interface.ral +22 -0
- package/dist/alephium-web3.min.js +0 -3
- package/dist/alephium-web3.min.js.LICENSE.txt +0 -12
- package/dist/alephium-web3.min.js.map +0 -1
- package/dist/scripts/check-versions.d.ts +0 -1
- package/dist/scripts/check-versions.js +0 -39
- package/dist/scripts/header.d.ts +0 -0
- package/dist/src/api/api-alephium.d.ts +0 -1716
- package/dist/src/api/api-alephium.js +0 -1284
- package/dist/src/api/api-explorer.d.ts +0 -923
- package/dist/src/api/api-explorer.js +0 -711
- package/dist/src/api/explorer-provider.d.ts +0 -20
- package/dist/src/api/explorer-provider.js +0 -69
- package/dist/src/api/index.d.ts +0 -6
- package/dist/src/api/index.js +0 -52
- package/dist/src/api/node-provider.d.ts +0 -23
- package/dist/src/api/node-provider.js +0 -93
- package/dist/src/api/types.d.ts +0 -38
- package/dist/src/api/types.js +0 -263
- package/dist/src/api/utils.d.ts +0 -12
- package/dist/src/api/utils.js +0 -59
- package/dist/src/constants.d.ts +0 -6
- package/dist/src/constants.js +0 -26
- package/dist/src/contract/contract.d.ts +0 -293
- package/dist/src/contract/contract.js +0 -1079
- package/dist/src/contract/events.d.ts +0 -11
- package/dist/src/contract/events.js +0 -65
- package/dist/src/contract/index.d.ts +0 -3
- package/dist/src/contract/index.js +0 -36
- package/dist/src/contract/ralph.d.ts +0 -13
- package/dist/src/contract/ralph.js +0 -397
- package/dist/src/global.d.ts +0 -7
- package/dist/src/global.js +0 -54
- package/dist/src/index.d.ts +0 -8
- package/dist/src/index.js +0 -57
- package/dist/src/signer/index.d.ts +0 -3
- package/dist/src/signer/index.js +0 -36
- package/dist/src/signer/signer.d.ts +0 -60
- package/dist/src/signer/signer.js +0 -236
- package/dist/src/signer/tx-builder.d.ts +0 -12
- package/dist/src/signer/tx-builder.js +0 -96
- package/dist/src/signer/types.d.ts +0 -115
- package/dist/src/signer/types.js +0 -30
- package/dist/src/transaction/index.d.ts +0 -2
- package/dist/src/transaction/index.js +0 -35
- package/dist/src/transaction/sign-verify.d.ts +0 -3
- package/dist/src/transaction/sign-verify.js +0 -52
- package/dist/src/transaction/status.d.ts +0 -11
- package/dist/src/transaction/status.js +0 -49
- package/dist/src/utils/address.d.ts +0 -1
- package/dist/src/utils/address.js +0 -42
- package/dist/src/utils/bs58.d.ts +0 -5
- package/dist/src/utils/bs58.js +0 -40
- package/dist/src/utils/djb2.d.ts +0 -1
- package/dist/src/utils/index.d.ts +0 -7
- package/dist/src/utils/index.js +0 -40
- package/dist/src/utils/number.d.ts +0 -18
- package/dist/src/utils/number.fixture.d.ts +0 -12
- package/dist/src/utils/number.fixture.js +0 -189
- package/dist/src/utils/number.js +0 -149
- package/dist/src/utils/sign.d.ts +0 -3
- package/dist/src/utils/sign.js +0 -89
- package/dist/src/utils/subscription.d.ts +0 -21
- package/dist/src/utils/subscription.js +0 -51
- package/dist/src/utils/utils.d.ts +0 -40
- package/dist/src/utils/utils.js +0 -244
- package/jest-config.json +0 -11
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ApiRequestArguments, ApiRequestHandler } from './types';
|
|
2
|
-
import { Api as ExplorerApi } from './api-explorer';
|
|
3
|
-
export declare class ExplorerProvider {
|
|
4
|
-
readonly blocks: ExplorerApi<string>['blocks'];
|
|
5
|
-
readonly transactions: ExplorerApi<string>['transactions'];
|
|
6
|
-
readonly addresses: ExplorerApi<string>['addresses'];
|
|
7
|
-
readonly infos: ExplorerApi<string>['infos'];
|
|
8
|
-
readonly mempool: ExplorerApi<string>['mempool'];
|
|
9
|
-
readonly tokens: ExplorerApi<string>['tokens'];
|
|
10
|
-
readonly charts: ExplorerApi<string>['charts'];
|
|
11
|
-
readonly contractEvents: ExplorerApi<string>['contractEvents'];
|
|
12
|
-
readonly contracts: ExplorerApi<string>['contracts'];
|
|
13
|
-
readonly utils: ExplorerApi<string>['utils'];
|
|
14
|
-
constructor(baseUrl: string, apiKey?: string, customFetch?: typeof fetch);
|
|
15
|
-
constructor(provider: ExplorerProvider);
|
|
16
|
-
constructor(handler: ApiRequestHandler);
|
|
17
|
-
request: (args: ApiRequestArguments) => Promise<any>;
|
|
18
|
-
static Proxy(explorerProvider: ExplorerProvider): ExplorerProvider;
|
|
19
|
-
static Remote(handler: ApiRequestHandler): ExplorerProvider;
|
|
20
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.ExplorerProvider = void 0;
|
|
21
|
-
const types_1 = require("./types");
|
|
22
|
-
const api_explorer_1 = require("./api-explorer");
|
|
23
|
-
const utils_1 = require("./utils");
|
|
24
|
-
function initializeExplorerApi(baseUrl, apiKey, customFetch) {
|
|
25
|
-
const explorerApi = new api_explorer_1.Api({
|
|
26
|
-
baseUrl: baseUrl,
|
|
27
|
-
baseApiParams: { secure: true },
|
|
28
|
-
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {}),
|
|
29
|
-
customFetch: customFetch ?? utils_1.DEFAULT_THROTTLE_FETCH
|
|
30
|
-
});
|
|
31
|
-
explorerApi.setSecurityData(apiKey ?? null);
|
|
32
|
-
return explorerApi;
|
|
33
|
-
}
|
|
34
|
-
class ExplorerProvider {
|
|
35
|
-
constructor(param0, apiKey, customFetch) {
|
|
36
|
-
this.request = (args) => {
|
|
37
|
-
return (0, types_1.request)(this, args);
|
|
38
|
-
};
|
|
39
|
-
let explorerApi;
|
|
40
|
-
if (typeof param0 === 'string') {
|
|
41
|
-
explorerApi = initializeExplorerApi(param0, apiKey, customFetch);
|
|
42
|
-
}
|
|
43
|
-
else if (typeof param0 === 'function') {
|
|
44
|
-
explorerApi = new ExplorerProvider('https://1.2.3.4:0');
|
|
45
|
-
(0, types_1.forwardRequests)(explorerApi, param0);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
explorerApi = param0;
|
|
49
|
-
}
|
|
50
|
-
this.blocks = { ...explorerApi.blocks };
|
|
51
|
-
this.transactions = { ...explorerApi.transactions };
|
|
52
|
-
this.addresses = { ...explorerApi.addresses };
|
|
53
|
-
this.infos = { ...explorerApi.infos };
|
|
54
|
-
this.mempool = { ...explorerApi.mempool };
|
|
55
|
-
this.tokens = { ...explorerApi.tokens };
|
|
56
|
-
this.charts = { ...explorerApi.charts };
|
|
57
|
-
this.utils = { ...explorerApi.utils };
|
|
58
|
-
this.contracts = { ...explorerApi.contracts };
|
|
59
|
-
this.contractEvents = { ...explorerApi.contractEvents };
|
|
60
|
-
}
|
|
61
|
-
// This can prevent the proxied explorer provider from being modified
|
|
62
|
-
static Proxy(explorerProvider) {
|
|
63
|
-
return new ExplorerProvider(explorerProvider);
|
|
64
|
-
}
|
|
65
|
-
static Remote(handler) {
|
|
66
|
-
return new ExplorerProvider(handler);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.ExplorerProvider = ExplorerProvider;
|
package/dist/src/api/index.d.ts
DELETED
package/dist/src/api/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
-
if (k2 === undefined) k2 = k;
|
|
21
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
22
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
-
}
|
|
25
|
-
Object.defineProperty(o, k2, desc);
|
|
26
|
-
}) : (function(o, m, k, k2) {
|
|
27
|
-
if (k2 === undefined) k2 = k;
|
|
28
|
-
o[k2] = m[k];
|
|
29
|
-
}));
|
|
30
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
31
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
-
}) : function(o, v) {
|
|
33
|
-
o["default"] = v;
|
|
34
|
-
});
|
|
35
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
-
};
|
|
38
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
39
|
-
if (mod && mod.__esModule) return mod;
|
|
40
|
-
var result = {};
|
|
41
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
42
|
-
__setModuleDefault(result, mod);
|
|
43
|
-
return result;
|
|
44
|
-
};
|
|
45
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.explorer = exports.node = void 0;
|
|
47
|
-
__exportStar(require("./node-provider"), exports);
|
|
48
|
-
__exportStar(require("./explorer-provider"), exports);
|
|
49
|
-
exports.node = __importStar(require("./api-alephium"));
|
|
50
|
-
exports.explorer = __importStar(require("./api-explorer"));
|
|
51
|
-
__exportStar(require("./types"), exports);
|
|
52
|
-
__exportStar(require("./utils"), exports);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ApiRequestArguments, ApiRequestHandler, TokenMetaData } from './types';
|
|
2
|
-
import { Api as NodeApi } from './api-alephium';
|
|
3
|
-
import { HexString } from '../contract';
|
|
4
|
-
export declare class NodeProvider {
|
|
5
|
-
readonly wallets: NodeApi<string>['wallets'];
|
|
6
|
-
readonly infos: NodeApi<string>['infos'];
|
|
7
|
-
readonly blockflow: NodeApi<string>['blockflow'];
|
|
8
|
-
readonly addresses: NodeApi<string>['addresses'];
|
|
9
|
-
readonly transactions: NodeApi<string>['transactions'];
|
|
10
|
-
readonly mempool: NodeApi<string>['mempool'];
|
|
11
|
-
readonly contracts: NodeApi<string>['contracts'];
|
|
12
|
-
readonly multisig: NodeApi<string>['multisig'];
|
|
13
|
-
readonly utils: NodeApi<string>['utils'];
|
|
14
|
-
readonly miners: NodeApi<string>['miners'];
|
|
15
|
-
readonly events: NodeApi<string>['events'];
|
|
16
|
-
constructor(baseUrl: string, apiKey?: string, customFetch?: typeof fetch);
|
|
17
|
-
constructor(provider: NodeProvider);
|
|
18
|
-
constructor(handler: ApiRequestHandler);
|
|
19
|
-
request: (args: ApiRequestArguments) => Promise<any>;
|
|
20
|
-
static Proxy(nodeProvider: NodeProvider): NodeProvider;
|
|
21
|
-
static Remote(handler: ApiRequestHandler): NodeProvider;
|
|
22
|
-
fetchStdTokenMetaData: (tokenId: HexString) => Promise<TokenMetaData>;
|
|
23
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.NodeProvider = void 0;
|
|
21
|
-
const types_1 = require("./types");
|
|
22
|
-
const api_alephium_1 = require("./api-alephium");
|
|
23
|
-
const utils_1 = require("./utils");
|
|
24
|
-
const utils_2 = require("../utils");
|
|
25
|
-
function initializeNodeApi(baseUrl, apiKey, customFetch) {
|
|
26
|
-
const nodeApi = new api_alephium_1.Api({
|
|
27
|
-
baseUrl: baseUrl,
|
|
28
|
-
baseApiParams: { secure: true },
|
|
29
|
-
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {}),
|
|
30
|
-
customFetch: customFetch ?? utils_1.DEFAULT_THROTTLE_FETCH
|
|
31
|
-
});
|
|
32
|
-
nodeApi.setSecurityData(apiKey ?? null);
|
|
33
|
-
return nodeApi;
|
|
34
|
-
}
|
|
35
|
-
class NodeProvider {
|
|
36
|
-
constructor(param0, apiKey, customFetch) {
|
|
37
|
-
this.request = (args) => {
|
|
38
|
-
return (0, types_1.request)(this, args);
|
|
39
|
-
};
|
|
40
|
-
// Only use this when the token is following the standard token interface
|
|
41
|
-
this.fetchStdTokenMetaData = async (tokenId) => {
|
|
42
|
-
return fetchStdTokenMetaData(this.contracts, tokenId);
|
|
43
|
-
};
|
|
44
|
-
let nodeApi;
|
|
45
|
-
if (typeof param0 === 'string') {
|
|
46
|
-
const api = initializeNodeApi(param0, apiKey, customFetch);
|
|
47
|
-
nodeApi = {
|
|
48
|
-
...api,
|
|
49
|
-
fetchStdTokenMetaData: async (tokenId) => fetchStdTokenMetaData(api.contracts, tokenId)
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
else if (typeof param0 === 'function') {
|
|
53
|
-
nodeApi = new NodeProvider('https://1.2.3.4:0');
|
|
54
|
-
(0, types_1.forwardRequests)(nodeApi, param0);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
nodeApi = param0;
|
|
58
|
-
}
|
|
59
|
-
this.wallets = { ...nodeApi.wallets };
|
|
60
|
-
this.infos = { ...nodeApi.infos };
|
|
61
|
-
this.blockflow = { ...nodeApi.blockflow };
|
|
62
|
-
this.addresses = { ...nodeApi.addresses };
|
|
63
|
-
this.transactions = { ...nodeApi.transactions };
|
|
64
|
-
this.mempool = { ...nodeApi.mempool };
|
|
65
|
-
this.contracts = { ...nodeApi.contracts };
|
|
66
|
-
this.multisig = { ...nodeApi.multisig };
|
|
67
|
-
this.utils = { ...nodeApi.utils };
|
|
68
|
-
this.miners = { ...nodeApi.miners };
|
|
69
|
-
this.events = { ...nodeApi.events };
|
|
70
|
-
}
|
|
71
|
-
// This can prevent the proxied node provider from being modified
|
|
72
|
-
static Proxy(nodeProvider) {
|
|
73
|
-
return new NodeProvider(nodeProvider);
|
|
74
|
-
}
|
|
75
|
-
static Remote(handler) {
|
|
76
|
-
return new NodeProvider(handler);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.NodeProvider = NodeProvider;
|
|
80
|
-
async function fetchStdTokenMetaData(contractAPI, tokenId) {
|
|
81
|
-
const group = 0;
|
|
82
|
-
const address = (0, utils_2.addressFromTokenId)(tokenId);
|
|
83
|
-
const calls = Array.from([0, 1, 2, 3], (index) => ({ methodIndex: index, group: group, address: address }));
|
|
84
|
-
const result = await contractAPI.postContractsMulticallContract({
|
|
85
|
-
calls: calls
|
|
86
|
-
});
|
|
87
|
-
return {
|
|
88
|
-
symbol: result.results[0].returns[0].value,
|
|
89
|
-
name: result.results[1].returns[0].value,
|
|
90
|
-
decimals: Number(result.results[2].returns[0].value),
|
|
91
|
-
totalSupply: BigInt(result.results[3].returns[0].value)
|
|
92
|
-
};
|
|
93
|
-
}
|
package/dist/src/api/types.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as node from './api-alephium';
|
|
2
|
-
export declare type Number256 = bigint | string;
|
|
3
|
-
export declare type Val = Number256 | boolean | string | Val[];
|
|
4
|
-
export declare type NamedVals = Record<string, Val>;
|
|
5
|
-
export interface Token {
|
|
6
|
-
id: string;
|
|
7
|
-
amount: Number256;
|
|
8
|
-
}
|
|
9
|
-
export declare function toApiToken(token: Token): node.Token;
|
|
10
|
-
export declare function toApiTokens(tokens?: Token[]): node.Token[] | undefined;
|
|
11
|
-
export declare function fromApiToken(token: node.Token): Token;
|
|
12
|
-
export declare function fromApiTokens(tokens?: node.Token[]): Token[] | undefined;
|
|
13
|
-
export declare function toApiBoolean(v: Val): boolean;
|
|
14
|
-
export declare function toApiNumber256(v: Val): string;
|
|
15
|
-
export declare function toApiNumber256Optional(v?: Val): string | undefined;
|
|
16
|
-
export declare function fromApiNumber256(n: string): bigint;
|
|
17
|
-
export declare function toApiByteVec(v: Val): string;
|
|
18
|
-
export declare function toApiAddress(v: Val): string;
|
|
19
|
-
export declare function toApiArray(tpe: string, v: Val): node.Val;
|
|
20
|
-
export declare function toApiVal(v: Val, tpe: string): node.Val;
|
|
21
|
-
export declare function fromApiVals(vals: node.Val[], names: string[], types: string[], optionalNames?: string[], optionalTypes?: string[]): NamedVals;
|
|
22
|
-
export declare function fromApiArray(vals: node.Val[], types: string[]): Val[];
|
|
23
|
-
export declare function fromApiVal(v: node.Val, tpe: string): Val;
|
|
24
|
-
export declare function typeLength(tpe: string): number;
|
|
25
|
-
export interface ApiRequestArguments {
|
|
26
|
-
path: string;
|
|
27
|
-
method: string;
|
|
28
|
-
params: any[];
|
|
29
|
-
}
|
|
30
|
-
export declare type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
|
|
31
|
-
export declare function forwardRequests(api: Record<string, any>, handler: ApiRequestHandler): void;
|
|
32
|
-
export declare function request(provider: Record<string, any>, args: ApiRequestArguments): Promise<any>;
|
|
33
|
-
export interface TokenMetaData {
|
|
34
|
-
name: string;
|
|
35
|
-
symbol: string;
|
|
36
|
-
decimals: number;
|
|
37
|
-
totalSupply: Number256;
|
|
38
|
-
}
|
package/dist/src/api/types.js
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.request = exports.forwardRequests = exports.typeLength = exports.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
|
|
21
|
-
const utils_1 = require("../utils");
|
|
22
|
-
utils_1.assertType;
|
|
23
|
-
function toApiToken(token) {
|
|
24
|
-
return { id: token.id, amount: toApiNumber256(token.amount) };
|
|
25
|
-
}
|
|
26
|
-
exports.toApiToken = toApiToken;
|
|
27
|
-
function toApiTokens(tokens) {
|
|
28
|
-
return tokens?.map(toApiToken);
|
|
29
|
-
}
|
|
30
|
-
exports.toApiTokens = toApiTokens;
|
|
31
|
-
function fromApiToken(token) {
|
|
32
|
-
return { id: token.id, amount: fromApiNumber256(token.amount) };
|
|
33
|
-
}
|
|
34
|
-
exports.fromApiToken = fromApiToken;
|
|
35
|
-
function fromApiTokens(tokens) {
|
|
36
|
-
return tokens?.map(fromApiToken);
|
|
37
|
-
}
|
|
38
|
-
exports.fromApiTokens = fromApiTokens;
|
|
39
|
-
function toApiBoolean(v) {
|
|
40
|
-
if (typeof v === 'boolean') {
|
|
41
|
-
return v;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
throw new Error(`Invalid boolean value: ${v}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.toApiBoolean = toApiBoolean;
|
|
48
|
-
// TODO: check integer bounds
|
|
49
|
-
function toApiNumber256(v) {
|
|
50
|
-
if ((typeof v === 'number' && Number.isInteger(v)) || typeof v === 'bigint') {
|
|
51
|
-
return v.toString();
|
|
52
|
-
}
|
|
53
|
-
else if (typeof v === 'string') {
|
|
54
|
-
return v;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
throw new Error(`Invalid 256 bit number: ${v}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.toApiNumber256 = toApiNumber256;
|
|
61
|
-
function toApiNumber256Optional(v) {
|
|
62
|
-
return v === undefined ? undefined : toApiNumber256(v);
|
|
63
|
-
}
|
|
64
|
-
exports.toApiNumber256Optional = toApiNumber256Optional;
|
|
65
|
-
function fromApiNumber256(n) {
|
|
66
|
-
return BigInt(n);
|
|
67
|
-
}
|
|
68
|
-
exports.fromApiNumber256 = fromApiNumber256;
|
|
69
|
-
// TODO: check hex string
|
|
70
|
-
function toApiByteVec(v) {
|
|
71
|
-
if (typeof v === 'string') {
|
|
72
|
-
// try to convert from address to contract id
|
|
73
|
-
try {
|
|
74
|
-
const address = utils_1.bs58.decode(v);
|
|
75
|
-
if (address.length == 33 && address[0] == 3) {
|
|
76
|
-
return Buffer.from(address.slice(1)).toString('hex');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (_) {
|
|
80
|
-
return v;
|
|
81
|
-
}
|
|
82
|
-
return v;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
throw new Error(`Invalid string: ${v}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.toApiByteVec = toApiByteVec;
|
|
89
|
-
function toApiAddress(v) {
|
|
90
|
-
if (typeof v === 'string') {
|
|
91
|
-
try {
|
|
92
|
-
utils_1.bs58.decode(v);
|
|
93
|
-
return v;
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
throw new Error(`Invalid base58 string: ${v}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
throw new Error(`Invalid string: ${v}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.toApiAddress = toApiAddress;
|
|
104
|
-
function toApiArray(tpe, v) {
|
|
105
|
-
if (!Array.isArray(v)) {
|
|
106
|
-
throw new Error(`Expected array, got ${v}`);
|
|
107
|
-
}
|
|
108
|
-
const semiColonIndex = tpe.lastIndexOf(';');
|
|
109
|
-
if (semiColonIndex == -1) {
|
|
110
|
-
throw new Error(`Invalid Val type: ${tpe}`);
|
|
111
|
-
}
|
|
112
|
-
const subType = tpe.slice(1, semiColonIndex);
|
|
113
|
-
const dim = parseInt(tpe.slice(semiColonIndex + 1, -1));
|
|
114
|
-
if (v.length != dim) {
|
|
115
|
-
throw new Error(`Invalid val dimension: ${v}`);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
return { value: v.map((v) => toApiVal(v, subType)), type: 'Array' };
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.toApiArray = toApiArray;
|
|
122
|
-
function toApiVal(v, tpe) {
|
|
123
|
-
if (tpe === 'Bool') {
|
|
124
|
-
return { value: toApiBoolean(v), type: tpe };
|
|
125
|
-
}
|
|
126
|
-
else if (tpe === 'U256' || tpe === 'I256') {
|
|
127
|
-
return { value: toApiNumber256(v), type: tpe };
|
|
128
|
-
}
|
|
129
|
-
else if (tpe === 'ByteVec') {
|
|
130
|
-
return { value: toApiByteVec(v), type: tpe };
|
|
131
|
-
}
|
|
132
|
-
else if (tpe === 'Address') {
|
|
133
|
-
return { value: toApiAddress(v), type: tpe };
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
return toApiArray(tpe, v);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.toApiVal = toApiVal;
|
|
140
|
-
function _fromApiVal(vals, valIndex, tpe) {
|
|
141
|
-
if (vals.length === 0) {
|
|
142
|
-
throw new Error('Not enough Vals');
|
|
143
|
-
}
|
|
144
|
-
const firstVal = vals[`${valIndex}`];
|
|
145
|
-
if (tpe === 'Bool' && firstVal.type === tpe) {
|
|
146
|
-
return [firstVal.value, valIndex + 1];
|
|
147
|
-
}
|
|
148
|
-
else if ((tpe === 'U256' || tpe === 'I256') && firstVal.type === tpe) {
|
|
149
|
-
return [fromApiNumber256(firstVal.value), valIndex + 1];
|
|
150
|
-
}
|
|
151
|
-
else if ((tpe === 'ByteVec' || tpe === 'Address') && firstVal.type === tpe) {
|
|
152
|
-
return [firstVal.value, valIndex + 1];
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
const [baseType, dims] = decodeArrayType(tpe);
|
|
156
|
-
const arraySize = dims.reduce((a, b) => a * b);
|
|
157
|
-
const nextIndex = valIndex + arraySize;
|
|
158
|
-
const valsToUse = vals.slice(valIndex, nextIndex);
|
|
159
|
-
if (valsToUse.length == arraySize && valsToUse.every((val) => val.type === baseType)) {
|
|
160
|
-
const localVals = valsToUse.map((val) => fromApiVal(val, baseType));
|
|
161
|
-
return [foldVals(localVals, dims), nextIndex];
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
throw new Error(`Invalid array Val type: ${valsToUse}, ${tpe}`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function fromApiVals(vals, names, types, optionalNames = [], optionalTypes = []) {
|
|
169
|
-
let valIndex = 0;
|
|
170
|
-
const result = {};
|
|
171
|
-
types.forEach((currentType, index) => {
|
|
172
|
-
const currentName = names[`${index}`];
|
|
173
|
-
const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType);
|
|
174
|
-
valIndex = nextIndex;
|
|
175
|
-
result[`${currentName}`] = val;
|
|
176
|
-
});
|
|
177
|
-
if (valIndex === vals.length) {
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
|
-
const optionalFields = fromApiVals(vals.slice(valIndex), optionalNames, optionalTypes);
|
|
181
|
-
return { ...result, ...optionalFields };
|
|
182
|
-
}
|
|
183
|
-
exports.fromApiVals = fromApiVals;
|
|
184
|
-
function fromApiArray(vals, types) {
|
|
185
|
-
let valIndex = 0;
|
|
186
|
-
const result = [];
|
|
187
|
-
for (const currentType of types) {
|
|
188
|
-
const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType);
|
|
189
|
-
result.push(val);
|
|
190
|
-
valIndex = nextIndex;
|
|
191
|
-
}
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
exports.fromApiArray = fromApiArray;
|
|
195
|
-
function fromApiVal(v, tpe) {
|
|
196
|
-
if (v.type === 'Bool' && v.type === tpe) {
|
|
197
|
-
return v.value;
|
|
198
|
-
}
|
|
199
|
-
else if ((v.type === 'U256' || v.type === 'I256') && v.type === tpe) {
|
|
200
|
-
return fromApiNumber256(v.value);
|
|
201
|
-
}
|
|
202
|
-
else if ((v.type === 'ByteVec' || v.type === 'Address') && v.type === tpe) {
|
|
203
|
-
return v.value;
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
throw new Error(`Invalid node.Val type: ${v}`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
exports.fromApiVal = fromApiVal;
|
|
210
|
-
function decodeArrayType(tpe) {
|
|
211
|
-
const semiColonIndex = tpe.lastIndexOf(';');
|
|
212
|
-
if (semiColonIndex === -1) {
|
|
213
|
-
throw new Error(`Invalid Val type: ${tpe}`);
|
|
214
|
-
}
|
|
215
|
-
const subType = tpe.slice(1, semiColonIndex);
|
|
216
|
-
const dim = parseInt(tpe.slice(semiColonIndex + 1, -1));
|
|
217
|
-
if (subType[0] == '[') {
|
|
218
|
-
const [baseType, subDim] = decodeArrayType(subType);
|
|
219
|
-
return [baseType, (subDim.unshift(dim), subDim)];
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
return [subType, [dim]];
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function foldVals(vals, dims) {
|
|
226
|
-
if (dims.length == 1) {
|
|
227
|
-
return vals;
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
const result = [];
|
|
231
|
-
const chunkSize = vals.length / dims[0];
|
|
232
|
-
const chunkDims = dims.slice(1);
|
|
233
|
-
for (let i = 0; i < vals.length; i += chunkSize) {
|
|
234
|
-
const chunk = vals.slice(i, i + chunkSize);
|
|
235
|
-
result.push(foldVals(chunk, chunkDims));
|
|
236
|
-
}
|
|
237
|
-
return result;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
function typeLength(tpe) {
|
|
241
|
-
if (tpe === 'U256' || tpe === 'I256' || tpe === 'Bool' || tpe === 'ByteVec' || tpe === 'Address') {
|
|
242
|
-
return 1;
|
|
243
|
-
}
|
|
244
|
-
const [, dims] = decodeArrayType(tpe);
|
|
245
|
-
return dims.reduce((a, b) => a * b);
|
|
246
|
-
}
|
|
247
|
-
exports.typeLength = typeLength;
|
|
248
|
-
function forwardRequests(api, handler) {
|
|
249
|
-
// Update class properties to forward requests
|
|
250
|
-
for (const [path, pathObject] of Object.entries(api)) {
|
|
251
|
-
for (const method of Object.keys(pathObject)) {
|
|
252
|
-
pathObject[`${method}`] = async (...params) => {
|
|
253
|
-
return handler({ path, method, params });
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
exports.forwardRequests = forwardRequests;
|
|
259
|
-
async function request(provider, args) {
|
|
260
|
-
const call = provider[`${args.path}`][`${args.method}`];
|
|
261
|
-
return call(...args.params);
|
|
262
|
-
}
|
|
263
|
-
exports.request = request;
|
package/dist/src/api/utils.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import 'cross-fetch/polyfill';
|
|
2
|
-
export declare function convertHttpResponse<T>(response: {
|
|
3
|
-
data: T;
|
|
4
|
-
error?: {
|
|
5
|
-
detail: string;
|
|
6
|
-
};
|
|
7
|
-
}): T;
|
|
8
|
-
export declare function retryFetch(...fetchParams: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
9
|
-
export declare function throttledFetch(ratePerSec: number): typeof fetch;
|
|
10
|
-
export declare const RETRY_LIMIT_WHEN_429 = 3;
|
|
11
|
-
export declare const DEFAULT_RATE_LIMIT = 3;
|
|
12
|
-
export declare const DEFAULT_THROTTLE_FETCH: typeof fetch;
|
package/dist/src/api/utils.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DEFAULT_THROTTLE_FETCH = exports.DEFAULT_RATE_LIMIT = exports.RETRY_LIMIT_WHEN_429 = exports.throttledFetch = exports.retryFetch = exports.convertHttpResponse = void 0;
|
|
21
|
-
require("cross-fetch/polyfill");
|
|
22
|
-
const utils_1 = require("../utils");
|
|
23
|
-
const async_sema_1 = require("async-sema");
|
|
24
|
-
function convertHttpResponse(response) {
|
|
25
|
-
if (response.error) {
|
|
26
|
-
throw new Error(`[API Error] - ${response.error.detail}`);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return response.data;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.convertHttpResponse = convertHttpResponse;
|
|
33
|
-
async function retryFetch(...fetchParams) {
|
|
34
|
-
const retry = async (retryCount) => {
|
|
35
|
-
const response = await fetch(...fetchParams);
|
|
36
|
-
if (response.status === 429 && retryCount < exports.RETRY_LIMIT_WHEN_429) {
|
|
37
|
-
const nextCount = retryCount + 1;
|
|
38
|
-
await (0, utils_1.sleep)(nextCount * 500);
|
|
39
|
-
return await retry(nextCount);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return response;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
return retry(0);
|
|
46
|
-
}
|
|
47
|
-
exports.retryFetch = retryFetch;
|
|
48
|
-
function throttledFetch(ratePerSec) {
|
|
49
|
-
const limit = (0, async_sema_1.RateLimit)(ratePerSec);
|
|
50
|
-
const customFetch = async (...fetchParams) => {
|
|
51
|
-
await limit();
|
|
52
|
-
return retryFetch(...fetchParams);
|
|
53
|
-
};
|
|
54
|
-
return customFetch;
|
|
55
|
-
}
|
|
56
|
-
exports.throttledFetch = throttledFetch;
|
|
57
|
-
exports.RETRY_LIMIT_WHEN_429 = 3;
|
|
58
|
-
exports.DEFAULT_RATE_LIMIT = 3;
|
|
59
|
-
exports.DEFAULT_THROTTLE_FETCH = throttledFetch(exports.DEFAULT_RATE_LIMIT);
|
package/dist/src/constants.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const TOTAL_NUMBER_OF_GROUPS = 4;
|
|
2
|
-
export declare const TOTAL_NUMBER_OF_CHAINS: number;
|
|
3
|
-
export declare const MIN_UTXO_SET_AMOUNT: bigint;
|
|
4
|
-
export declare const ALPH_TOKEN_ID: string;
|
|
5
|
-
export declare const ONE_ALPH: bigint;
|
|
6
|
-
export declare const DUST_AMOUNT: bigint;
|
package/dist/src/constants.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
21
|
-
exports.TOTAL_NUMBER_OF_GROUPS = 4;
|
|
22
|
-
exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS * exports.TOTAL_NUMBER_OF_GROUPS;
|
|
23
|
-
exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
|
|
24
|
-
exports.ALPH_TOKEN_ID = ''.padStart(64, '0');
|
|
25
|
-
exports.ONE_ALPH = 10n ** 18n;
|
|
26
|
-
exports.DUST_AMOUNT = 10n ** 15n;
|