@ckb-ccc/core 0.0.4-alpha.8 → 0.0.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/signer/btc/signerBtcPublicKeyReadonly.d.ts +12 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
- package/dist/signer/btc/signerBtcPublicKeyReadonly.js +16 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +12 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbScriptReadonly.js +16 -0
- package/dist/signer/evm/signerEvm.d.ts +5 -1
- package/dist/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist/signer/evm/signerEvm.js +20 -6
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts +13 -1
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
- package/dist/signer/evm/signerEvmAddressReadonly.js +16 -0
- package/dist/signer/helpers.d.ts.map +1 -1
- package/dist/signer/helpers.js +3 -2
- package/dist/signer/signer.d.ts +16 -4
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +5 -2
- package/dist.commonjs/address/address.advanced.d.ts +65 -0
- package/dist.commonjs/address/address.advanced.d.ts.map +1 -0
- package/dist.commonjs/address/address.advanced.js +149 -0
- package/dist.commonjs/address/advanced.d.ts +2 -0
- package/dist.commonjs/address/advanced.d.ts.map +1 -0
- package/dist.commonjs/address/advanced.js +17 -0
- package/dist.commonjs/address/index.d.ts +54 -0
- package/dist.commonjs/address/index.d.ts.map +1 -0
- package/dist.commonjs/address/index.js +84 -0
- package/dist.commonjs/advanced.d.ts +3 -0
- package/dist.commonjs/advanced.d.ts.map +1 -0
- package/dist.commonjs/advanced.js +31 -0
- package/dist.commonjs/advancedBarrel.d.ts +5 -0
- package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.js +20 -0
- package/dist.commonjs/barrel.d.ts +11 -0
- package/dist.commonjs/barrel.d.ts.map +1 -0
- package/dist.commonjs/barrel.js +26 -0
- package/dist.commonjs/bytes/advanced.d.ts +5 -0
- package/dist.commonjs/bytes/advanced.d.ts.map +1 -0
- package/dist.commonjs/bytes/advanced.js +2 -0
- package/dist.commonjs/bytes/index.d.ts +64 -0
- package/dist.commonjs/bytes/index.d.ts.map +1 -0
- package/dist.commonjs/bytes/index.js +97 -0
- package/dist.commonjs/ckb/advanced.d.ts +4 -0
- package/dist.commonjs/ckb/advanced.d.ts.map +1 -0
- package/dist.commonjs/ckb/advanced.js +32 -0
- package/dist.commonjs/ckb/index.d.ts +3 -0
- package/dist.commonjs/ckb/index.d.ts.map +1 -0
- package/dist.commonjs/ckb/index.js +18 -0
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +355 -0
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts.map +1 -0
- package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -0
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +6 -0
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts.map +1 -0
- package/dist.commonjs/ckb/molecule.advanced/index.js +25 -0
- package/dist.commonjs/ckb/script.advanced.d.ts +5 -0
- package/dist.commonjs/ckb/script.advanced.d.ts.map +1 -0
- package/dist.commonjs/ckb/script.advanced.js +16 -0
- package/dist.commonjs/ckb/script.d.ts +126 -0
- package/dist.commonjs/ckb/script.d.ts.map +1 -0
- package/dist.commonjs/ckb/script.js +188 -0
- package/dist.commonjs/ckb/transaction.advanced.d.ts +5 -0
- package/dist.commonjs/ckb/transaction.advanced.d.ts.map +1 -0
- package/dist.commonjs/ckb/transaction.advanced.js +12 -0
- package/dist.commonjs/ckb/transaction.d.ts +533 -0
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -0
- package/dist.commonjs/ckb/transaction.js +665 -0
- package/dist.commonjs/client/advanced.d.ts +4 -0
- package/dist.commonjs/client/advanced.d.ts.map +1 -0
- package/dist.commonjs/client/advanced.js +19 -0
- package/dist.commonjs/client/client.d.ts +19 -0
- package/dist.commonjs/client/client.d.ts.map +1 -0
- package/dist.commonjs/client/client.js +30 -0
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -0
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +26 -0
- package/dist.commonjs/client/clientPublicMainnet.d.ts +9 -0
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicMainnet.js +17 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +4 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +26 -0
- package/dist.commonjs/client/clientPublicTestnet.d.ts +9 -0
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -0
- package/dist.commonjs/client/clientPublicTestnet.js +17 -0
- package/dist.commonjs/client/clientTypes.d.ts +8 -0
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -0
- package/dist.commonjs/client/clientTypes.js +2 -0
- package/dist.commonjs/client/index.d.ts +6 -0
- package/dist.commonjs/client/index.d.ts.map +1 -0
- package/dist.commonjs/client/index.js +21 -0
- package/dist.commonjs/client/jsonRpc/advanced.d.ts +3 -0
- package/dist.commonjs/client/jsonRpc/advanced.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/advanced.js +18 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts +68 -0
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/index.js +128 -0
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +28 -0
- package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/transformers.js +126 -0
- package/dist.commonjs/client/jsonRpc/types.d.ts +41 -0
- package/dist.commonjs/client/jsonRpc/types.d.ts.map +1 -0
- package/dist.commonjs/client/jsonRpc/types.js +2 -0
- package/dist.commonjs/fixedPoint/index.d.ts +49 -0
- package/dist.commonjs/fixedPoint/index.d.ts.map +1 -0
- package/dist.commonjs/fixedPoint/index.js +65 -0
- package/dist.commonjs/hasher/advanced.d.ts +2 -0
- package/dist.commonjs/hasher/advanced.d.ts.map +1 -0
- package/dist.commonjs/hasher/advanced.js +4 -0
- package/dist.commonjs/hasher/index.d.ts +52 -0
- package/dist.commonjs/hasher/index.d.ts.map +1 -0
- package/dist.commonjs/hasher/index.js +68 -0
- package/dist.commonjs/hex/index.d.ts +24 -0
- package/dist.commonjs/hex/index.d.ts.map +1 -0
- package/dist.commonjs/hex/index.js +20 -0
- package/dist.commonjs/index.d.ts +3 -0
- package/dist.commonjs/index.d.ts.map +1 -0
- package/dist.commonjs/index.js +31 -0
- package/dist.commonjs/num/index.d.ts +112 -0
- package/dist.commonjs/num/index.d.ts.map +1 -0
- package/dist.commonjs/num/index.js +139 -0
- package/dist.commonjs/signer/btc/index.d.ts +3 -0
- package/dist.commonjs/signer/btc/index.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/index.js +18 -0
- package/dist.commonjs/signer/btc/signerBtc.d.ts +50 -0
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/signerBtc.js +71 -0
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +60 -0
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +72 -0
- package/dist.commonjs/signer/ckb/index.d.ts +2 -0
- package/dist.commonjs/signer/ckb/index.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/index.js +17 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +59 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +71 -0
- package/dist.commonjs/signer/evm/index.d.ts +3 -0
- package/dist.commonjs/signer/evm/index.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/index.js +18 -0
- package/dist.commonjs/signer/evm/signerEvm.d.ts +46 -0
- package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/signerEvm.js +83 -0
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +52 -0
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +62 -0
- package/dist.commonjs/signer/helpers.d.ts +40 -0
- package/dist.commonjs/signer/helpers.d.ts.map +1 -0
- package/dist.commonjs/signer/helpers.js +96 -0
- package/dist.commonjs/signer/index.d.ts +6 -0
- package/dist.commonjs/signer/index.d.ts.map +1 -0
- package/dist.commonjs/signer/index.js +21 -0
- package/dist.commonjs/signer/signer.d.ts +125 -0
- package/dist.commonjs/signer/signer.d.ts.map +1 -0
- package/dist.commonjs/signer/signer.js +109 -0
- package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +1 -0
- package/dist.commonjs/utils/index.d.ts +7 -0
- package/dist.commonjs/utils/index.d.ts.map +1 -0
- package/dist.commonjs/utils/index.js +10 -0
- package/package.json +20 -7
- package/src/signer/btc/signerBtcPublicKeyReadonly.ts +18 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +18 -0
- package/src/signer/evm/signerEvm.ts +55 -12
- package/src/signer/evm/signerEvmAddressReadonly.ts +19 -1
- package/src/signer/helpers.ts +5 -3
- package/src/signer/signer.ts +20 -3
- package/tsconfig.base.json +21 -0
- package/tsconfig.commonjs.json +8 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Hex } from "../../hex";
|
|
2
|
+
export type JsonRpcPayload = {
|
|
3
|
+
id: number;
|
|
4
|
+
jsonrpc: "2.0";
|
|
5
|
+
method: string;
|
|
6
|
+
params: unknown[] | Record<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export type JsonRpcHashType = "type" | "data" | "data1" | "data2";
|
|
9
|
+
export type JsonRpcDepType = "dep_group" | "code";
|
|
10
|
+
export type JsonRpcScript = {
|
|
11
|
+
code_hash: Hex;
|
|
12
|
+
hash_type: JsonRpcHashType;
|
|
13
|
+
args: Hex;
|
|
14
|
+
};
|
|
15
|
+
export type JsonRpcOutPoint = {
|
|
16
|
+
index: Hex;
|
|
17
|
+
tx_hash: Hex;
|
|
18
|
+
};
|
|
19
|
+
export type JsonRpcCellInput = {
|
|
20
|
+
previous_output: JsonRpcOutPoint;
|
|
21
|
+
since: Hex;
|
|
22
|
+
};
|
|
23
|
+
export type JsonRpcCellOutput = {
|
|
24
|
+
capacity: Hex;
|
|
25
|
+
lock: JsonRpcScript;
|
|
26
|
+
type?: JsonRpcScript;
|
|
27
|
+
};
|
|
28
|
+
export type JsonRpcCellDep = {
|
|
29
|
+
out_point: JsonRpcOutPoint;
|
|
30
|
+
dep_type: JsonRpcDepType;
|
|
31
|
+
};
|
|
32
|
+
export type JsonRpcTransaction = {
|
|
33
|
+
version: Hex;
|
|
34
|
+
cell_deps: JsonRpcCellDep[];
|
|
35
|
+
header_deps: Hex[];
|
|
36
|
+
inputs: JsonRpcCellInput[];
|
|
37
|
+
outputs: JsonRpcCellOutput[];
|
|
38
|
+
outputs_data: Hex[];
|
|
39
|
+
witnesses: Hex[];
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/client/jsonRpc/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAClE,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,MAAM,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,GAAG,CAAC;IACf,SAAS,EAAE,eAAe,CAAC;IAC3B,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,eAAe,EAAE,eAAe,CAAC;IACjC,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,GAAG,CAAC;IACd,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,eAAe,CAAC;IAC3B,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,GAAG,CAAC;IACb,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,WAAW,EAAE,GAAG,EAAE,CAAC;IACnB,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,YAAY,EAAE,GAAG,EAAE,CAAC;IACpB,SAAS,EAAE,GAAG,EAAE,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a fixed point value as a bigint.
|
|
3
|
+
*/
|
|
4
|
+
export type FixedPoint = bigint;
|
|
5
|
+
/**
|
|
6
|
+
* Represents a value that can be converted to a fixed point value.
|
|
7
|
+
* It can be a bigint, string, or number.
|
|
8
|
+
*/
|
|
9
|
+
export type FixedPointLike = bigint | string | number;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a FixedPointLike value to its string representation with fixed-point decimals.
|
|
12
|
+
*
|
|
13
|
+
* @param val - The value to convert, which can be a bigint, string, or number.
|
|
14
|
+
* @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
|
|
15
|
+
* @returns A string representing the fixed-point value.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
|
|
20
|
+
* const strFromString = fixedPointToString("123456789", 8); // Outputs "1.23456789"
|
|
21
|
+
* const strFromNumber = fixedPointToString(123456789, 8); // Outputs "1.23456789"
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function fixedPointToString(val: FixedPointLike, decimals?: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a FixedPointLike value to a FixedPoint (bigint) with fixed-point decimals.
|
|
27
|
+
*
|
|
28
|
+
* @param val - The value to convert, which can be a bigint, string, or number.
|
|
29
|
+
* @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
|
|
30
|
+
* @returns A FixedPoint (bigint) representing the value with fixed-point decimals.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const fixedPoint = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
35
|
+
* const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
|
|
36
|
+
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function fixedPointFrom(val: FixedPointLike, decimals?: number): FixedPoint;
|
|
40
|
+
/**
|
|
41
|
+
* Represents the fixed point value of zero as a bigint.
|
|
42
|
+
*/
|
|
43
|
+
export declare const Zero = 0n;
|
|
44
|
+
/**
|
|
45
|
+
* Represents the fixed point value of one as a FixedPoint (bigint).
|
|
46
|
+
* Equivalent to 1 in fixed-point representation with default decimals (8).
|
|
47
|
+
*/
|
|
48
|
+
export declare const One: bigint;
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixedPoint/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;;GAGG;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEtD;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,SAAI,GAAG,MAAM,CAS5E;AAED;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,SAAI,GAAG,UAAU,CAY5E;AAED;;GAEG;AAEH,eAAO,MAAM,IAAI,KAAK,CAAC;AAEvB;;;GAGG;AAEH,eAAO,MAAM,GAAG,QAAsB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a fixed point value as a bigint.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.One = exports.Zero = exports.fixedPointFrom = exports.fixedPointToString = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a FixedPointLike value to its string representation with fixed-point decimals.
|
|
9
|
+
*
|
|
10
|
+
* @param val - The value to convert, which can be a bigint, string, or number.
|
|
11
|
+
* @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
|
|
12
|
+
* @returns A string representing the fixed-point value.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const str = fixedPointToString(123456789n, 8); // Outputs "1.23456789"
|
|
17
|
+
* const strFromString = fixedPointToString("123456789", 8); // Outputs "1.23456789"
|
|
18
|
+
* const strFromNumber = fixedPointToString(123456789, 8); // Outputs "1.23456789"
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function fixedPointToString(val, decimals = 8) {
|
|
22
|
+
const str = fixedPointFrom(val).toString();
|
|
23
|
+
const l = str.length <= decimals ? "0" : str.slice(0, -decimals);
|
|
24
|
+
const r = str.slice(-decimals).padStart(decimals, "0").replace(/0*$/, "");
|
|
25
|
+
if (r === "") {
|
|
26
|
+
return l;
|
|
27
|
+
}
|
|
28
|
+
return `${l}.${r}`;
|
|
29
|
+
}
|
|
30
|
+
exports.fixedPointToString = fixedPointToString;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a FixedPointLike value to a FixedPoint (bigint) with fixed-point decimals.
|
|
33
|
+
*
|
|
34
|
+
* @param val - The value to convert, which can be a bigint, string, or number.
|
|
35
|
+
* @param decimals - The number of decimal places for the fixed-point representation. Default is 8.
|
|
36
|
+
* @returns A FixedPoint (bigint) representing the value with fixed-point decimals.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const fixedPoint = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
41
|
+
* const fixedPointFromString = fixedPointFrom("1.23456789", 8); // Outputs 123456789n
|
|
42
|
+
* const fixedPointFromNumber = fixedPointFrom(1.23456789, 8); // Outputs 123456789n
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function fixedPointFrom(val, decimals = 8) {
|
|
46
|
+
if (typeof val === "bigint") {
|
|
47
|
+
return val;
|
|
48
|
+
}
|
|
49
|
+
const [l, r] = val.toString().split(".");
|
|
50
|
+
const lVal = BigInt(l.padEnd(l.length + decimals, "0"));
|
|
51
|
+
if (r === undefined) {
|
|
52
|
+
return lVal;
|
|
53
|
+
}
|
|
54
|
+
return lVal + BigInt(r.slice(0, decimals).padEnd(decimals, "0"));
|
|
55
|
+
}
|
|
56
|
+
exports.fixedPointFrom = fixedPointFrom;
|
|
57
|
+
/**
|
|
58
|
+
* Represents the fixed point value of zero as a bigint.
|
|
59
|
+
*/
|
|
60
|
+
exports.Zero = 0n;
|
|
61
|
+
/**
|
|
62
|
+
* Represents the fixed point value of one as a FixedPoint (bigint).
|
|
63
|
+
* Equivalent to 1 in fixed-point representation with default decimals (8).
|
|
64
|
+
*/
|
|
65
|
+
exports.One = fixedPointFrom("1");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/hasher/advanced.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BytesLike } from "../bytes";
|
|
2
|
+
import { Hex } from "../hex";
|
|
3
|
+
export declare class Hasher {
|
|
4
|
+
private readonly hasher;
|
|
5
|
+
/**
|
|
6
|
+
* Creates an instance of Hasher.
|
|
7
|
+
*
|
|
8
|
+
* @param outLength - The output length of the hash in bytes. Default is 32.
|
|
9
|
+
* @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
|
|
10
|
+
*/
|
|
11
|
+
constructor(outLength?: number, personal?: string);
|
|
12
|
+
/**
|
|
13
|
+
* Updates the hash with the given data.
|
|
14
|
+
*
|
|
15
|
+
* @param data - The data to update the hash with.
|
|
16
|
+
* @returns The current Hasher instance for chaining.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const hasher = new Hasher();
|
|
21
|
+
* hasher.update("some data").update("more data");
|
|
22
|
+
* const hash = hasher.digest();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
update(data: BytesLike): Hasher;
|
|
26
|
+
/**
|
|
27
|
+
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
28
|
+
*
|
|
29
|
+
* @returns The hexadecimal string representation of the hash.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const hasher = new Hasher();
|
|
34
|
+
* hasher.update("some data");
|
|
35
|
+
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
digest(): Hex;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Computes the CKB hash of the given data using the Blake2b algorithm.
|
|
42
|
+
*
|
|
43
|
+
* @param data - The data to hash.
|
|
44
|
+
* @returns The hexadecimal string representation of the hash.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const hash = ckbHash("some data"); // Outputs something like "0x..."
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function ckbHash(data: BytesLike): Hex;
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hasher/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAa,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAG7B,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IAEjC;;;;;OAKG;gBAES,SAAS,SAAK,EAAE,QAAQ,SAAuB;IAS3D;;;;;;;;;;;;OAYG;IAEH,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM;IAK/B;;;;;;;;;;;OAWG;IAEH,MAAM,IAAI,GAAG;CAGd;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,GAAG,CAE5C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ckbHash = exports.Hasher = void 0;
|
|
7
|
+
const blake2b_1 = __importDefault(require("blake2b"));
|
|
8
|
+
const bytes_1 = require("../bytes");
|
|
9
|
+
const advanced_1 = require("./advanced");
|
|
10
|
+
class Hasher {
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of Hasher.
|
|
13
|
+
*
|
|
14
|
+
* @param outLength - The output length of the hash in bytes. Default is 32.
|
|
15
|
+
* @param personal - The personal string for the Blake2b algorithm. Default is CKB_BLAKE2B_PERSONAL.
|
|
16
|
+
*/
|
|
17
|
+
constructor(outLength = 32, personal = advanced_1.CKB_BLAKE2B_PERSONAL) {
|
|
18
|
+
this.hasher = (0, blake2b_1.default)(outLength, undefined, undefined, (0, bytes_1.bytesFrom)(personal, "utf8"));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Updates the hash with the given data.
|
|
22
|
+
*
|
|
23
|
+
* @param data - The data to update the hash with.
|
|
24
|
+
* @returns The current Hasher instance for chaining.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const hasher = new Hasher();
|
|
29
|
+
* hasher.update("some data").update("more data");
|
|
30
|
+
* const hash = hasher.digest();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
update(data) {
|
|
34
|
+
this.hasher.update((0, bytes_1.bytesFrom)(data));
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Finalizes the hash and returns the digest as a hexadecimal string.
|
|
39
|
+
*
|
|
40
|
+
* @returns The hexadecimal string representation of the hash.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const hasher = new Hasher();
|
|
45
|
+
* hasher.update("some data");
|
|
46
|
+
* const hash = hasher.digest(); // Outputs something like "0x..."
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
digest() {
|
|
50
|
+
return `0x${this.hasher.digest("hex")}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.Hasher = Hasher;
|
|
54
|
+
/**
|
|
55
|
+
* Computes the CKB hash of the given data using the Blake2b algorithm.
|
|
56
|
+
*
|
|
57
|
+
* @param data - The data to hash.
|
|
58
|
+
* @returns The hexadecimal string representation of the hash.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const hash = ckbHash("some data"); // Outputs something like "0x..."
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function ckbHash(data) {
|
|
66
|
+
return new Hasher().update(data).digest();
|
|
67
|
+
}
|
|
68
|
+
exports.ckbHash = ckbHash;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BytesLike } from "../bytes";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a hexadecimal string prefixed with "0x".
|
|
4
|
+
*/
|
|
5
|
+
export type Hex = `0x${string}`;
|
|
6
|
+
/**
|
|
7
|
+
* Represents a value that can be converted to a hexadecimal string.
|
|
8
|
+
* It extends the BytesLike type.
|
|
9
|
+
*/
|
|
10
|
+
export type HexLike = BytesLike;
|
|
11
|
+
/**
|
|
12
|
+
* Converts a HexLike value to a Hex string.
|
|
13
|
+
*
|
|
14
|
+
* @param hex - The value to convert, which can be a string, Uint8Array, ArrayBuffer, or number array.
|
|
15
|
+
* @returns A Hex string representing the value.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const hexString = hexFrom("68656c6c6f"); // Outputs "0x68656c6c6f"
|
|
20
|
+
* const hexStringFromBytes = hexFrom(new Uint8Array([104, 101, 108, 108, 111])); // Outputs "0x68656c6c6f"
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function hexFrom(hex: HexLike): Hex;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hex/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAW,MAAM,UAAU,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAChC;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC;AAEhC;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAEzC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hexFrom = void 0;
|
|
4
|
+
const bytes_1 = require("../bytes");
|
|
5
|
+
/**
|
|
6
|
+
* Converts a HexLike value to a Hex string.
|
|
7
|
+
*
|
|
8
|
+
* @param hex - The value to convert, which can be a string, Uint8Array, ArrayBuffer, or number array.
|
|
9
|
+
* @returns A Hex string representing the value.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const hexString = hexFrom("68656c6c6f"); // Outputs "0x68656c6c6f"
|
|
14
|
+
* const hexStringFromBytes = hexFrom(new Uint8Array([104, 101, 108, 108, 111])); // Outputs "0x68656c6c6f"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function hexFrom(hex) {
|
|
18
|
+
return `0x${(0, bytes_1.bytesTo)((0, bytes_1.bytesFrom)(hex), "hex")}`;
|
|
19
|
+
}
|
|
20
|
+
exports.hexFrom = hexFrom;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.ccc = void 0;
|
|
30
|
+
__exportStar(require("./barrel"), exports);
|
|
31
|
+
exports.ccc = __importStar(require("./barrel"));
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Bytes, BytesLike } from "../bytes";
|
|
2
|
+
import { Hex, HexLike } from "../hex";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a numeric value as a bigint.
|
|
5
|
+
*/
|
|
6
|
+
export type Num = bigint;
|
|
7
|
+
/**
|
|
8
|
+
* Represents a value that can be converted to a numeric value.
|
|
9
|
+
* It can be a string, number, bigint, or HexLike.
|
|
10
|
+
*/
|
|
11
|
+
export type NumLike = string | number | bigint | HexLike;
|
|
12
|
+
/**
|
|
13
|
+
* Converts a NumLike value to a Num (bigint).
|
|
14
|
+
*
|
|
15
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
16
|
+
* @returns A Num (bigint) representing the value.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const num = numFrom("12345"); // Outputs 12345n
|
|
21
|
+
* const numFromHex = numFrom("0x3039"); // Outputs 12345n
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function numFrom(val: NumLike): Num;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a NumLike value to a hexadecimal string.
|
|
27
|
+
*
|
|
28
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
29
|
+
* @returns A Hex string representing the numeric value.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const hex = numToHex(12345); // Outputs "0x3039"
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function numToHex(val: NumLike): Hex;
|
|
37
|
+
/**
|
|
38
|
+
* Converts a NumLike value to a byte array in little-endian order.
|
|
39
|
+
*
|
|
40
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
41
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
42
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const bytes = numToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function numToBytes(val: NumLike, bytes?: number): Bytes;
|
|
50
|
+
/**
|
|
51
|
+
* Converts a NumLike value to a byte array in little-endian order.
|
|
52
|
+
*
|
|
53
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
54
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
55
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const bytes = numLeToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function numLeToBytes(val: NumLike, bytes?: number): Bytes;
|
|
63
|
+
/**
|
|
64
|
+
* Converts a NumLike value to a byte array in big-endian order.
|
|
65
|
+
*
|
|
66
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
67
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
68
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const bytes = numBeToBytes(12345, 4); // Outputs Uint8Array [0, 0, 48, 57]
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function numBeToBytes(val: NumLike, bytes?: number): Bytes;
|
|
76
|
+
/**
|
|
77
|
+
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
78
|
+
*
|
|
79
|
+
* @param val - The byte array to convert.
|
|
80
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const num = numFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function numFromBytes(val: BytesLike): Num;
|
|
88
|
+
/**
|
|
89
|
+
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
90
|
+
*
|
|
91
|
+
* @param val - The byte array to convert.
|
|
92
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const num = numLeFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function numLeFromBytes(val: BytesLike): Num;
|
|
100
|
+
/**
|
|
101
|
+
* Converts a byte array to a Num (bigint) assuming big-endian order.
|
|
102
|
+
*
|
|
103
|
+
* @param val - The byte array to convert.
|
|
104
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const num = numBeFromBytes(new Uint8Array([0, 0, 48, 57])); // Outputs 12345n
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function numBeFromBytes(val: BytesLike): Num;
|
|
112
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/num/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAA0B,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,QAAQ,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAUzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,CAE1C;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAE9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAEhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAUhE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAEhD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAElD"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.numBeFromBytes = exports.numLeFromBytes = exports.numFromBytes = exports.numBeToBytes = exports.numLeToBytes = exports.numToBytes = exports.numToHex = exports.numFrom = void 0;
|
|
4
|
+
const bytes_1 = require("../bytes");
|
|
5
|
+
const hex_1 = require("../hex");
|
|
6
|
+
/**
|
|
7
|
+
* Converts a NumLike value to a Num (bigint).
|
|
8
|
+
*
|
|
9
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
10
|
+
* @returns A Num (bigint) representing the value.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const num = numFrom("12345"); // Outputs 12345n
|
|
15
|
+
* const numFromHex = numFrom("0x3039"); // Outputs 12345n
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function numFrom(val) {
|
|
19
|
+
if (typeof val === "bigint") {
|
|
20
|
+
return val;
|
|
21
|
+
}
|
|
22
|
+
if (typeof val === "string" || typeof val === "number") {
|
|
23
|
+
return BigInt(val);
|
|
24
|
+
}
|
|
25
|
+
return BigInt((0, hex_1.hexFrom)(val));
|
|
26
|
+
}
|
|
27
|
+
exports.numFrom = numFrom;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a NumLike value to a hexadecimal string.
|
|
30
|
+
*
|
|
31
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
32
|
+
* @returns A Hex string representing the numeric value.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const hex = numToHex(12345); // Outputs "0x3039"
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function numToHex(val) {
|
|
40
|
+
return `0x${numFrom(val).toString(16)}`;
|
|
41
|
+
}
|
|
42
|
+
exports.numToHex = numToHex;
|
|
43
|
+
/**
|
|
44
|
+
* Converts a NumLike value to a byte array in little-endian order.
|
|
45
|
+
*
|
|
46
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
47
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
48
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const bytes = numToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
function numToBytes(val, bytes) {
|
|
56
|
+
return numLeToBytes(val, bytes);
|
|
57
|
+
}
|
|
58
|
+
exports.numToBytes = numToBytes;
|
|
59
|
+
/**
|
|
60
|
+
* Converts a NumLike value to a byte array in little-endian order.
|
|
61
|
+
*
|
|
62
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
63
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
64
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const bytes = numLeToBytes(12345, 4); // Outputs Uint8Array [57, 48, 0, 0]
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
function numLeToBytes(val, bytes) {
|
|
72
|
+
return numBeToBytes(val, bytes).reverse();
|
|
73
|
+
}
|
|
74
|
+
exports.numLeToBytes = numLeToBytes;
|
|
75
|
+
/**
|
|
76
|
+
* Converts a NumLike value to a byte array in big-endian order.
|
|
77
|
+
*
|
|
78
|
+
* @param val - The value to convert, which can be a string, number, bigint, or HexLike.
|
|
79
|
+
* @param bytes - The number of bytes to use for the representation. If not provided, the exact number of bytes needed is used.
|
|
80
|
+
* @returns A Uint8Array containing the byte representation of the numeric value.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const bytes = numBeToBytes(12345, 4); // Outputs Uint8Array [0, 0, 48, 57]
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
function numBeToBytes(val, bytes) {
|
|
88
|
+
const rawBytes = (0, bytes_1.bytesFrom)(numFrom(val).toString(16));
|
|
89
|
+
if (bytes == null) {
|
|
90
|
+
return rawBytes;
|
|
91
|
+
}
|
|
92
|
+
return (0, bytes_1.bytesConcat)(Array.from(Array(bytes - rawBytes.length), () => 0), rawBytes);
|
|
93
|
+
}
|
|
94
|
+
exports.numBeToBytes = numBeToBytes;
|
|
95
|
+
/**
|
|
96
|
+
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
97
|
+
*
|
|
98
|
+
* @param val - The byte array to convert.
|
|
99
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const num = numFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
function numFromBytes(val) {
|
|
107
|
+
return numLeFromBytes(val);
|
|
108
|
+
}
|
|
109
|
+
exports.numFromBytes = numFromBytes;
|
|
110
|
+
/**
|
|
111
|
+
* Converts a byte array to a Num (bigint) assuming little-endian order.
|
|
112
|
+
*
|
|
113
|
+
* @param val - The byte array to convert.
|
|
114
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const num = numLeFromBytes(new Uint8Array([57, 48, 0, 0])); // Outputs 12345n
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
function numLeFromBytes(val) {
|
|
122
|
+
return numBeFromBytes((0, bytes_1.bytesFrom)(val).reverse());
|
|
123
|
+
}
|
|
124
|
+
exports.numLeFromBytes = numLeFromBytes;
|
|
125
|
+
/**
|
|
126
|
+
* Converts a byte array to a Num (bigint) assuming big-endian order.
|
|
127
|
+
*
|
|
128
|
+
* @param val - The byte array to convert.
|
|
129
|
+
* @returns A Num (bigint) representing the numeric value.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const num = numBeFromBytes(new Uint8Array([0, 0, 48, 57])); // Outputs 12345n
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
function numBeFromBytes(val) {
|
|
137
|
+
return numFrom((0, bytes_1.bytesFrom)(val));
|
|
138
|
+
}
|
|
139
|
+
exports.numBeFromBytes = numBeFromBytes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/btc/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC"}
|