@alephium/web3 0.8.2-test.2 → 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,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 __importStar = (this && this.__importStar) || function (mod) {
|
|
36
|
-
if (mod && mod.__esModule) return mod;
|
|
37
|
-
var result = {};
|
|
38
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
39
|
-
__setModuleDefault(result, mod);
|
|
40
|
-
return result;
|
|
41
|
-
};
|
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.transactionVerifySignature = exports.transactionSign = void 0;
|
|
44
|
-
const utils = __importStar(require("../utils"));
|
|
45
|
-
function transactionSign(txId, privateKey, keyType) {
|
|
46
|
-
return utils.sign(txId, privateKey, keyType);
|
|
47
|
-
}
|
|
48
|
-
exports.transactionSign = transactionSign;
|
|
49
|
-
function transactionVerifySignature(txId, publicKey, signature, keyType) {
|
|
50
|
-
return utils.verifySignature(txId, publicKey, signature, keyType);
|
|
51
|
-
}
|
|
52
|
-
exports.transactionVerifySignature = transactionVerifySignature;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { node } from '../api';
|
|
2
|
-
import { Subscription, SubscribeOptions } from '../utils';
|
|
3
|
-
export declare type TxStatus = node.TxStatus;
|
|
4
|
-
export declare class TxStatusSubscription extends Subscription<TxStatus> {
|
|
5
|
-
readonly txId: string;
|
|
6
|
-
readonly fromGroup?: number;
|
|
7
|
-
readonly toGroup?: number;
|
|
8
|
-
constructor(options: SubscribeOptions<TxStatus>, txId: string, fromGroup?: number, toGroup?: number);
|
|
9
|
-
polling(): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export declare function subscribeToTxStatus(options: SubscribeOptions<TxStatus>, txId: string, fromGroup?: number, toGroup?: number): TxStatusSubscription;
|
|
@@ -1,49 +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.subscribeToTxStatus = exports.TxStatusSubscription = void 0;
|
|
21
|
-
const __1 = require("..");
|
|
22
|
-
const utils_1 = require("../utils");
|
|
23
|
-
class TxStatusSubscription extends utils_1.Subscription {
|
|
24
|
-
constructor(options, txId, fromGroup, toGroup) {
|
|
25
|
-
super(options);
|
|
26
|
-
this.txId = txId;
|
|
27
|
-
this.fromGroup = fromGroup;
|
|
28
|
-
this.toGroup = toGroup;
|
|
29
|
-
this.startPolling();
|
|
30
|
-
}
|
|
31
|
-
async polling() {
|
|
32
|
-
try {
|
|
33
|
-
const txStatus = await __1.web3.getCurrentNodeProvider().transactions.getTransactionsStatus({
|
|
34
|
-
txId: this.txId,
|
|
35
|
-
fromGroup: this.fromGroup,
|
|
36
|
-
toGroup: this.toGroup
|
|
37
|
-
});
|
|
38
|
-
await this.messageCallback(txStatus);
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
await this.errorCallback(err, this);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.TxStatusSubscription = TxStatusSubscription;
|
|
46
|
-
function subscribeToTxStatus(options, txId, fromGroup, toGroup) {
|
|
47
|
-
return new TxStatusSubscription(options, txId, fromGroup, toGroup);
|
|
48
|
-
}
|
|
49
|
-
exports.subscribeToTxStatus = subscribeToTxStatus;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function addressToGroup(address: string, totalNumberOfGroups: number): number;
|
|
@@ -1,42 +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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.addressToGroup = void 0;
|
|
24
|
-
const bs58_1 = __importDefault(require("./bs58"));
|
|
25
|
-
const djb2_1 = __importDefault(require("./djb2"));
|
|
26
|
-
function addressToGroup(address, totalNumberOfGroups) {
|
|
27
|
-
const bytes = bs58_1.default.decode(address).slice(1);
|
|
28
|
-
const value = (0, djb2_1.default)(bytes) | 1;
|
|
29
|
-
const hash = toPosInt(xorByte(value));
|
|
30
|
-
const group = hash % totalNumberOfGroups;
|
|
31
|
-
return group;
|
|
32
|
-
}
|
|
33
|
-
exports.addressToGroup = addressToGroup;
|
|
34
|
-
function xorByte(value) {
|
|
35
|
-
const byte0 = value >> 24;
|
|
36
|
-
const byte1 = value >> 16;
|
|
37
|
-
const byte2 = value >> 8;
|
|
38
|
-
return byte0 ^ byte1 ^ byte2 ^ value;
|
|
39
|
-
}
|
|
40
|
-
function toPosInt(byte) {
|
|
41
|
-
return byte & 0xff;
|
|
42
|
-
}
|
package/dist/src/utils/bs58.d.ts
DELETED
package/dist/src/utils/bs58.js
DELETED
|
@@ -1,40 +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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.isBase58 = exports.bs58 = void 0;
|
|
24
|
-
/** This source is under MIT License and come originally from https://github.com/cryptocoinjs/bs58 **/
|
|
25
|
-
const base_x_1 = __importDefault(require("base-x"));
|
|
26
|
-
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
27
|
-
exports.bs58 = (0, base_x_1.default)(ALPHABET);
|
|
28
|
-
function isBase58(s) {
|
|
29
|
-
if (s === '' || s.trim() === '') {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
return exports.bs58.encode(exports.bs58.decode(s)) === s;
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.isBase58 = isBase58;
|
|
40
|
-
exports.default = exports.bs58;
|
package/dist/src/utils/djb2.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function djb2(bytes: Uint8Array): number;
|
package/dist/src/utils/index.js
DELETED
|
@@ -1,40 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
31
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
__exportStar(require("./address"), exports);
|
|
35
|
-
__exportStar(require("./bs58"), exports);
|
|
36
|
-
__exportStar(require("./djb2"), exports);
|
|
37
|
-
__exportStar(require("./utils"), exports);
|
|
38
|
-
__exportStar(require("./subscription"), exports);
|
|
39
|
-
__exportStar(require("./sign"), exports);
|
|
40
|
-
__exportStar(require("./number"), exports);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Number256 } from '..';
|
|
2
|
-
export declare const isNumeric: (numToCheck: any) => boolean;
|
|
3
|
-
export interface IPrettifyNumberConfig {
|
|
4
|
-
minDecimalPlaces: number;
|
|
5
|
-
maxDecimalPlaces: number;
|
|
6
|
-
/** significant digits to show in decimals while respecting decimal places */
|
|
7
|
-
minDecimalSignificantDigits: number;
|
|
8
|
-
/** special case for zero, e.g. we may want to display $0.00 or 0.0 ALPH */
|
|
9
|
-
decimalPlacesWhenZero: number;
|
|
10
|
-
}
|
|
11
|
-
export declare const prettifyNumberConfig: Record<string, IPrettifyNumberConfig>;
|
|
12
|
-
export declare function prettifyAttoAlphAmount(amount: Number256): string | undefined;
|
|
13
|
-
export declare function prettifyTokenAmount(amount: Number256, decimals: number): string | undefined;
|
|
14
|
-
export declare function prettifyExactAmount(amount: Number256, decimals: number): string | undefined;
|
|
15
|
-
export declare function prettifyNumber(amount: Number256, decimals: number, config: IPrettifyNumberConfig): string | undefined;
|
|
16
|
-
export declare function convertAmountWithDecimals(amount: string | number, decimals: number): bigint | undefined;
|
|
17
|
-
export declare function convertAlphAmountWithDecimals(amount: string | number): bigint | undefined;
|
|
18
|
-
export declare function number256ToBigint(number: Number256): bigint;
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tests1 = exports.tests = void 0;
|
|
4
|
-
/*
|
|
5
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
6
|
-
This file is part of the alephium project.
|
|
7
|
-
|
|
8
|
-
The library is free software: you can redistribute it and/or modify
|
|
9
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
11
|
-
(at your option) any later version.
|
|
12
|
-
|
|
13
|
-
The library is distributed in the hope that it will be useful,
|
|
14
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
-
GNU Lesser General Public License for more details.
|
|
17
|
-
|
|
18
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
19
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
-
*/
|
|
21
|
-
exports.tests = [
|
|
22
|
-
{
|
|
23
|
-
raw: 123456n,
|
|
24
|
-
decimal: 5,
|
|
25
|
-
exact: '1.23456',
|
|
26
|
-
alphFormat: '1.23',
|
|
27
|
-
tokenFormat: '1.2346'
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
raw: 12345612n,
|
|
31
|
-
decimal: 2,
|
|
32
|
-
exact: '123,456.12',
|
|
33
|
-
alphFormat: '123,456.12',
|
|
34
|
-
tokenFormat: '123,456.12'
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
raw: 123456123456n,
|
|
38
|
-
decimal: 6,
|
|
39
|
-
exact: '123,456.123456',
|
|
40
|
-
alphFormat: '123,456.12',
|
|
41
|
-
tokenFormat: '123,456.1235'
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
raw: 12n,
|
|
45
|
-
decimal: 2,
|
|
46
|
-
exact: '0.12',
|
|
47
|
-
alphFormat: '0.12',
|
|
48
|
-
tokenFormat: '0.12'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
raw: 123456n,
|
|
52
|
-
decimal: 6,
|
|
53
|
-
exact: '0.123456',
|
|
54
|
-
alphFormat: '0.12',
|
|
55
|
-
tokenFormat: '0.1235'
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
raw: 123456n,
|
|
59
|
-
decimal: 7,
|
|
60
|
-
exact: '0.0123456',
|
|
61
|
-
alphFormat: '0.012',
|
|
62
|
-
tokenFormat: '0.0123'
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
raw: 123456n,
|
|
66
|
-
decimal: 8,
|
|
67
|
-
exact: '0.00123456',
|
|
68
|
-
alphFormat: '0.0012',
|
|
69
|
-
tokenFormat: '0.0012'
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
raw: 123456n,
|
|
73
|
-
decimal: 9,
|
|
74
|
-
exact: '0.000123456',
|
|
75
|
-
alphFormat: '0.00012',
|
|
76
|
-
tokenFormat: '0.00012'
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
raw: 123456n,
|
|
80
|
-
decimal: 11,
|
|
81
|
-
exact: '0.00000123456',
|
|
82
|
-
alphFormat: '0.0000012',
|
|
83
|
-
tokenFormat: '0.0000012'
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
raw: -123456n,
|
|
87
|
-
decimal: 11,
|
|
88
|
-
exact: '-0.00000123456',
|
|
89
|
-
alphFormat: '-0.0000012',
|
|
90
|
-
tokenFormat: '-0.0000012'
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
raw: 8923088n,
|
|
94
|
-
decimal: 10,
|
|
95
|
-
exact: '0.0008923088',
|
|
96
|
-
alphFormat: '0.00089',
|
|
97
|
-
tokenFormat: '0.00089'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
raw: 885n,
|
|
101
|
-
decimal: 6,
|
|
102
|
-
exact: '0.000885',
|
|
103
|
-
alphFormat: '0.00089',
|
|
104
|
-
tokenFormat: '0.00089'
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
raw: 100000000000n,
|
|
108
|
-
decimal: 18,
|
|
109
|
-
exact: '0.0000001',
|
|
110
|
-
alphFormat: '0.0000001',
|
|
111
|
-
tokenFormat: '0.0000001'
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
raw: 1504000000000000000n,
|
|
115
|
-
decimal: 18,
|
|
116
|
-
exact: '1.504',
|
|
117
|
-
alphFormat: '1.50',
|
|
118
|
-
tokenFormat: '1.504'
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
raw: 1505000000000000000n,
|
|
122
|
-
decimal: 18,
|
|
123
|
-
exact: '1.505',
|
|
124
|
-
alphFormat: '1.51',
|
|
125
|
-
tokenFormat: '1.505'
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
raw: 1500050000000000000n,
|
|
129
|
-
decimal: 18,
|
|
130
|
-
exact: '1.50005',
|
|
131
|
-
alphFormat: '1.50',
|
|
132
|
-
tokenFormat: '1.5001'
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
raw: 100n,
|
|
136
|
-
decimal: 0,
|
|
137
|
-
exact: '100',
|
|
138
|
-
alphFormat: '100.00',
|
|
139
|
-
tokenFormat: '100.0'
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
raw: 123456789n,
|
|
143
|
-
decimal: 0,
|
|
144
|
-
exact: '123,456,789',
|
|
145
|
-
alphFormat: '123,456,789.00',
|
|
146
|
-
tokenFormat: '123,456,789.0'
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
raw: -123456789n,
|
|
150
|
-
decimal: 0,
|
|
151
|
-
exact: '-123,456,789',
|
|
152
|
-
alphFormat: '-123,456,789.00',
|
|
153
|
-
tokenFormat: '-123,456,789.0'
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
raw: 0n,
|
|
157
|
-
decimal: 0,
|
|
158
|
-
exact: '0',
|
|
159
|
-
alphFormat: '0.00',
|
|
160
|
-
tokenFormat: '0.0'
|
|
161
|
-
}
|
|
162
|
-
];
|
|
163
|
-
exports.tests1 = [
|
|
164
|
-
{
|
|
165
|
-
raw: '0',
|
|
166
|
-
decimals: 18,
|
|
167
|
-
amount: 0n
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
raw: '1.23',
|
|
171
|
-
decimals: 2,
|
|
172
|
-
amount: 123n
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
raw: '1',
|
|
176
|
-
decimals: 5,
|
|
177
|
-
amount: 100000n
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
raw: '1',
|
|
181
|
-
decimals: 18,
|
|
182
|
-
amount: 1000000000000000000n
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
raw: '1.23456789',
|
|
186
|
-
decimals: 18,
|
|
187
|
-
amount: 1234567890000000000n
|
|
188
|
-
}
|
|
189
|
-
];
|
package/dist/src/utils/number.js
DELETED
|
@@ -1,149 +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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.number256ToBigint = exports.convertAlphAmountWithDecimals = exports.convertAmountWithDecimals = exports.prettifyNumber = exports.prettifyExactAmount = exports.prettifyTokenAmount = exports.prettifyAttoAlphAmount = exports.prettifyNumberConfig = exports.isNumeric = void 0;
|
|
24
|
-
// Credits:
|
|
25
|
-
// 1. https://github.com/argentlabs/argent-x/blob/e63affa7f28b27333dca4081a3dcd375bb2da40b/packages/extension/src/shared/utils/number.ts
|
|
26
|
-
// 2. https://github.com/ethers-io/ethers.js/blob/724881f34d428406488a1c9f9dbebe54b6edecda/src.ts/utils/fixednumber.ts
|
|
27
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
28
|
-
const isNumeric = (numToCheck) => !isNaN(parseFloat(numToCheck)) && isFinite(numToCheck);
|
|
29
|
-
exports.isNumeric = isNumeric;
|
|
30
|
-
exports.prettifyNumberConfig = {
|
|
31
|
-
ALPH: {
|
|
32
|
-
minDecimalPlaces: 2,
|
|
33
|
-
maxDecimalPlaces: 10,
|
|
34
|
-
minDecimalSignificantDigits: 2,
|
|
35
|
-
decimalPlacesWhenZero: 2
|
|
36
|
-
},
|
|
37
|
-
TOKEN: {
|
|
38
|
-
minDecimalPlaces: 4,
|
|
39
|
-
maxDecimalPlaces: 16,
|
|
40
|
-
minDecimalSignificantDigits: 2,
|
|
41
|
-
decimalPlacesWhenZero: 1
|
|
42
|
-
},
|
|
43
|
-
Exact: {
|
|
44
|
-
minDecimalPlaces: 18,
|
|
45
|
-
maxDecimalPlaces: 18,
|
|
46
|
-
minDecimalSignificantDigits: 0,
|
|
47
|
-
decimalPlacesWhenZero: 0
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
function prettifyAttoAlphAmount(amount) {
|
|
51
|
-
return prettifyNumber(amount, 18, exports.prettifyNumberConfig.ALPH);
|
|
52
|
-
}
|
|
53
|
-
exports.prettifyAttoAlphAmount = prettifyAttoAlphAmount;
|
|
54
|
-
function prettifyTokenAmount(amount, decimals) {
|
|
55
|
-
return prettifyNumber(amount, decimals, exports.prettifyNumberConfig.TOKEN);
|
|
56
|
-
}
|
|
57
|
-
exports.prettifyTokenAmount = prettifyTokenAmount;
|
|
58
|
-
function prettifyExactAmount(amount, decimals) {
|
|
59
|
-
return prettifyNumber(amount, decimals, exports.prettifyNumberConfig.Exact);
|
|
60
|
-
}
|
|
61
|
-
exports.prettifyExactAmount = prettifyExactAmount;
|
|
62
|
-
function prettifyNumber(amount, decimals, config) {
|
|
63
|
-
const number = toFixedNumber(number256ToBigint(amount), decimals);
|
|
64
|
-
if (!(0, exports.isNumeric)(number)) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
const numberBN = new bignumber_js_1.default(number);
|
|
68
|
-
let untrimmed;
|
|
69
|
-
if (numberBN.gte(1)) {
|
|
70
|
-
/** simplest case, formatting to minDecimalPlaces will look good */
|
|
71
|
-
untrimmed = numberBN.toFormat(config.minDecimalPlaces);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
/** now need to interrogate the appearance of decimal number < 1 */
|
|
75
|
-
/** longest case - max decimal places e.g. 0.0008923088123 -> 0.0008923088 */
|
|
76
|
-
const maxDecimalPlacesString = numberBN.toFormat(config.maxDecimalPlaces);
|
|
77
|
-
/** count the zeros, which will then allow us to know the final length with desired significant digits */
|
|
78
|
-
const decimalPart = maxDecimalPlacesString.split('.')[1];
|
|
79
|
-
const zeroMatches = decimalPart?.match(/^0+/);
|
|
80
|
-
const leadingZerosInDecimalPart = zeroMatches && zeroMatches.length ? zeroMatches[0].length : 0;
|
|
81
|
-
/** now we can re-format with leadingZerosInDecimalPart + maxDecimalSignificanDigits to give us the pretty version */
|
|
82
|
-
/** e.g. 0.0008923088123 -> 0.00089 */
|
|
83
|
-
const prettyDecimalPlaces = Math.max(leadingZerosInDecimalPart + config.minDecimalSignificantDigits, config.minDecimalPlaces);
|
|
84
|
-
untrimmed = numberBN.toFormat(prettyDecimalPlaces);
|
|
85
|
-
}
|
|
86
|
-
/** the untrimmed string may have trailing zeros, e.g. 0.0890 */
|
|
87
|
-
/** trim to a minimum specified by the config, e.g. we may want to display $0.00 or 0.0 ETH */
|
|
88
|
-
let trimmed = untrimmed.replace(/0+$/, '');
|
|
89
|
-
const minLength = 1 + untrimmed.indexOf('.') + config.decimalPlacesWhenZero;
|
|
90
|
-
if (trimmed.length < minLength) {
|
|
91
|
-
trimmed = untrimmed.substring(0, minLength);
|
|
92
|
-
}
|
|
93
|
-
if (trimmed[trimmed.length - 1] === '.') {
|
|
94
|
-
trimmed = trimmed.slice(0, -1);
|
|
95
|
-
}
|
|
96
|
-
return trimmed;
|
|
97
|
-
}
|
|
98
|
-
exports.prettifyNumber = prettifyNumber;
|
|
99
|
-
const BN_N1 = BigInt(-1);
|
|
100
|
-
const BN_0 = BigInt(0);
|
|
101
|
-
// Constant to pull zeros from for multipliers
|
|
102
|
-
const Zeros = '0000';
|
|
103
|
-
function toFixedNumber(val, decimals) {
|
|
104
|
-
let negative = '';
|
|
105
|
-
if (val < BN_0) {
|
|
106
|
-
negative = '-';
|
|
107
|
-
val *= BN_N1;
|
|
108
|
-
}
|
|
109
|
-
let str = val.toString();
|
|
110
|
-
// No decimal point for whole values
|
|
111
|
-
if (decimals === 0) {
|
|
112
|
-
return negative + str;
|
|
113
|
-
}
|
|
114
|
-
// Pad out to the whole component (including a whole digit)
|
|
115
|
-
while (str.length <= decimals) {
|
|
116
|
-
str = Zeros + str;
|
|
117
|
-
}
|
|
118
|
-
// Insert the decimal point
|
|
119
|
-
const index = str.length - decimals;
|
|
120
|
-
str = str.substring(0, index) + '.' + str.substring(index);
|
|
121
|
-
// Trim the whole component (leaving at least one 0)
|
|
122
|
-
while (str[0] === '0' && str[1] !== '.') {
|
|
123
|
-
str = str.substring(1);
|
|
124
|
-
}
|
|
125
|
-
// Trim the decimal component (leaving at least one 0)
|
|
126
|
-
while (str[str.length - 1] === '0' && str[str.length - 2] !== '.') {
|
|
127
|
-
str = str.substring(0, str.length - 1);
|
|
128
|
-
}
|
|
129
|
-
return negative + str;
|
|
130
|
-
}
|
|
131
|
-
function convertAmountWithDecimals(amount, decimals) {
|
|
132
|
-
try {
|
|
133
|
-
const result = new bignumber_js_1.default(amount).multipliedBy(Math.pow(10, decimals));
|
|
134
|
-
return BigInt(result.toFormat(0, { groupSeparator: '' }));
|
|
135
|
-
}
|
|
136
|
-
catch (e) {
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
exports.convertAmountWithDecimals = convertAmountWithDecimals;
|
|
141
|
-
// E.g. `1.23 ALPH` will be converted to `1230000000000000000`
|
|
142
|
-
function convertAlphAmountWithDecimals(amount) {
|
|
143
|
-
return convertAmountWithDecimals(amount, 18);
|
|
144
|
-
}
|
|
145
|
-
exports.convertAlphAmountWithDecimals = convertAlphAmountWithDecimals;
|
|
146
|
-
function number256ToBigint(number) {
|
|
147
|
-
return typeof number === 'string' ? BigInt(number) : number;
|
|
148
|
-
}
|
|
149
|
-
exports.number256ToBigint = number256ToBigint;
|
package/dist/src/utils/sign.d.ts
DELETED