@ckb-ccc/core 0.0.16-alpha.3 → 0.1.0-alpha.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/CHANGELOG.md +6 -0
- package/dist/bytes/index.d.ts +1 -1
- package/dist/bytes/index.d.ts.map +1 -1
- package/dist/bytes/index.js +14 -13
- package/dist/ckb/transaction.d.ts +6 -6
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +1 -0
- package/dist/client/client.d.ts +3 -46
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +3 -42
- package/dist/client/clientPublicMainnet.advanced.d.ts +2 -5
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.advanced.js +1 -1
- package/dist/client/clientPublicMainnet.d.ts +6 -11
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +2 -5
- package/dist/client/clientPublicTestnet.advanced.d.ts +2 -5
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.advanced.js +1 -1
- package/dist/client/clientPublicTestnet.d.ts +6 -11
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +2 -5
- package/dist/client/clientTypes.d.ts +60 -1
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/clientTypes.js +53 -1
- package/dist/client/jsonRpc/index.d.ts +9 -20
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +10 -3
- package/dist/client/transports/http.d.ts.map +1 -1
- package/dist/client/transports/http.js +2 -0
- package/dist/client/transports/webSocket.d.ts.map +1 -1
- package/dist/client/transports/webSocket.js +10 -5
- package/dist/signer/ckb/verifyJoyId.d.ts.map +1 -1
- package/dist/signer/ckb/verifyJoyId.js +1 -0
- package/dist/signer/nostr/signerNostr.js +1 -1
- package/dist/signer/nostr/verify.d.ts.map +1 -1
- package/dist/signer/nostr/verify.js +1 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist.commonjs/address/address.advanced.js +3 -3
- package/dist.commonjs/bytes/index.d.ts +1 -1
- package/dist.commonjs/bytes/index.d.ts.map +1 -1
- package/dist.commonjs/bytes/index.js +17 -17
- package/dist.commonjs/ckb/molecule.advanced/generated.js +33 -34
- package/dist.commonjs/ckb/molecule.advanced/index.js +1 -2
- package/dist.commonjs/ckb/script.js +4 -4
- package/dist.commonjs/ckb/transaction.d.ts +6 -6
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +9 -8
- package/dist.commonjs/client/cache/memory.advanced.js +5 -6
- package/dist.commonjs/client/client.d.ts +3 -46
- package/dist.commonjs/client/client.d.ts.map +1 -1
- package/dist.commonjs/client/client.js +2 -42
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +2 -5
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +21 -21
- package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -11
- package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicMainnet.js +2 -5
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +2 -5
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +21 -21
- package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -11
- package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist.commonjs/client/clientPublicTestnet.js +2 -5
- package/dist.commonjs/client/clientTypes.advanced.js +1 -2
- package/dist.commonjs/client/clientTypes.d.ts +60 -1
- package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
- package/dist.commonjs/client/clientTypes.js +55 -1
- package/dist.commonjs/client/jsonRpc/index.d.ts +9 -20
- package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
- package/dist.commonjs/client/jsonRpc/index.js +9 -2
- package/dist.commonjs/client/transports/advanced.js +1 -2
- package/dist.commonjs/client/transports/http.d.ts.map +1 -1
- package/dist.commonjs/client/transports/http.js +2 -0
- package/dist.commonjs/client/transports/webSocket.d.ts.map +1 -1
- package/dist.commonjs/client/transports/webSocket.js +10 -5
- package/dist.commonjs/fixedPoint/index.js +3 -3
- package/dist.commonjs/hasher/hasherCkb.js +3 -3
- package/dist.commonjs/hex/index.js +1 -2
- package/dist.commonjs/keystore/index.js +2 -3
- package/dist.commonjs/num/index.js +10 -11
- package/dist.commonjs/signer/btc/verify.js +1 -2
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +2 -3
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts.map +1 -1
- package/dist.commonjs/signer/ckb/verifyJoyId.js +2 -2
- package/dist.commonjs/signer/evm/verify.js +1 -2
- package/dist.commonjs/signer/nostr/signerNostr.js +1 -1
- package/dist.commonjs/signer/nostr/verify.d.ts.map +1 -1
- package/dist.commonjs/signer/nostr/verify.js +3 -3
- package/dist.commonjs/utils/index.d.ts +1 -1
- package/dist.commonjs/utils/index.d.ts.map +1 -1
- package/dist.commonjs/utils/index.js +4 -5
- package/package.json +4 -3
- package/src/bytes/index.ts +15 -14
- package/src/ckb/transaction.ts +1 -0
- package/src/client/client.ts +7 -62
- package/src/client/clientPublicMainnet.advanced.ts +329 -333
- package/src/client/clientPublicMainnet.ts +3 -11
- package/src/client/clientPublicTestnet.advanced.ts +341 -344
- package/src/client/clientPublicTestnet.ts +3 -11
- package/src/client/clientTypes.ts +87 -0
- package/src/client/jsonRpc/index.ts +29 -15
- package/src/client/transports/http.ts +2 -0
- package/src/client/transports/webSocket.ts +15 -8
- package/src/signer/ckb/verifyJoyId.ts +5 -1
- package/src/signer/nostr/signerNostr.ts +1 -1
- package/src/signer/nostr/verify.ts +2 -1
- package/src/utils/index.ts +1 -1
- package/dist/fixedPoint/index.test.d.ts +0 -2
- package/dist/fixedPoint/index.test.d.ts.map +0 -1
- package/dist/fixedPoint/index.test.js +0 -43
- package/dist.commonjs/fixedPoint/index.test.d.ts +0 -2
- package/dist.commonjs/fixedPoint/index.test.d.ts.map +0 -1
- package/dist.commonjs/fixedPoint/index.test.js +0 -45
- package/src/fixedPoint/index.test.ts +0 -55
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.apply = apply;
|
|
4
|
+
exports.reduceAsync = reduceAsync;
|
|
5
|
+
exports.sleep = sleep;
|
|
6
|
+
exports.isWebview = isWebview;
|
|
4
7
|
const index_js_1 = require("../num/index.js");
|
|
5
8
|
/**
|
|
6
9
|
* A type safe way to apply a transformer on a value if it's not empty.
|
|
@@ -16,7 +19,6 @@ function apply(transformer, value) {
|
|
|
16
19
|
}
|
|
17
20
|
return transformer(value);
|
|
18
21
|
}
|
|
19
|
-
exports.apply = apply;
|
|
20
22
|
/**
|
|
21
23
|
* Similar to Array.reduce, but the accumulator can returns Promise.
|
|
22
24
|
* @public
|
|
@@ -36,15 +38,12 @@ async function reduceAsync(values, accumulator, init) {
|
|
|
36
38
|
}
|
|
37
39
|
return values.reduce((current, b, i, array) => current.then((v) => Promise.resolve(accumulator(v, b, i, array)).then((r) => r ?? v)), Promise.resolve(init));
|
|
38
40
|
}
|
|
39
|
-
exports.reduceAsync = reduceAsync;
|
|
40
41
|
function sleep(ms) {
|
|
41
42
|
return new Promise((resolve) => setTimeout(resolve, Number((0, index_js_1.numFrom)(ms))));
|
|
42
43
|
}
|
|
43
|
-
exports.sleep = sleep;
|
|
44
44
|
/**
|
|
45
45
|
* @public
|
|
46
46
|
*/
|
|
47
47
|
function isWebview(userAgent) {
|
|
48
48
|
return /webview|wv|ip((?!.*Safari)|(?=.*like Safari))/i.test(userAgent);
|
|
49
49
|
}
|
|
50
|
-
exports.isWebview = isWebview;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0-alpha.4",
|
|
4
4
|
"description": "Core of CCC - CKBer's Codebase",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"@eslint/js": "^9.1.1",
|
|
35
35
|
"@types/blake2b": "^2.1.3",
|
|
36
36
|
"@types/jest": "^29.5.12",
|
|
37
|
+
"@types/ws": "^8.5.12",
|
|
37
38
|
"copyfiles": "^2.4.1",
|
|
38
39
|
"eslint": "^9.1.0",
|
|
39
40
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"scripts": {
|
|
68
69
|
"test": "jest",
|
|
69
70
|
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
|
|
70
|
-
"lint": "eslint",
|
|
71
|
-
"format": "prettier --write . && eslint --fix"
|
|
71
|
+
"lint": "eslint ./src",
|
|
72
|
+
"format": "prettier --write . && eslint --fix ./src"
|
|
72
73
|
}
|
|
73
74
|
}
|
package/src/bytes/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type Bytes = Uint8Array;
|
|
|
8
8
|
/**
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
|
-
export type BytesLike = string | Uint8Array | ArrayBuffer | number
|
|
11
|
+
export type BytesLike = string | Uint8Array | ArrayBuffer | ArrayLike<number>;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Concatenates multiple byte-like arrays into a single byte array.
|
|
@@ -98,22 +98,23 @@ export function bytesFrom(
|
|
|
98
98
|
return new Uint8Array(bytes);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
if (
|
|
102
|
-
if (
|
|
103
|
-
|
|
101
|
+
if (typeof bytes === "string") {
|
|
102
|
+
if (encoding !== undefined) {
|
|
103
|
+
return Buffer.from(bytes, encoding);
|
|
104
104
|
}
|
|
105
|
-
return new Uint8Array(bytes);
|
|
106
|
-
}
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
const str = bytes.startsWith("0x") ? bytes.slice(2) : bytes;
|
|
107
|
+
const paddedStr = str.length % 2 === 0 ? str : `0${str}`;
|
|
108
|
+
const data = Buffer.from(paddedStr, "hex");
|
|
109
|
+
if (data.length * 2 !== paddedStr.length) {
|
|
110
|
+
throw new Error(`Invalid bytes ${bytes}`);
|
|
111
|
+
}
|
|
112
|
+
return data;
|
|
110
113
|
}
|
|
111
114
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (data.length * 2 !== paddedStr.length) {
|
|
116
|
-
throw new Error(`Invalid bytes ${bytes}`);
|
|
115
|
+
const bytesArr = Array.from(bytes);
|
|
116
|
+
if (bytesArr.some((v) => v < 0 || 0xff < v)) {
|
|
117
|
+
throw new Error(`Invalid bytes ${JSON.stringify(bytes)}`);
|
|
117
118
|
}
|
|
118
|
-
return
|
|
119
|
+
return new Uint8Array(bytes);
|
|
119
120
|
}
|
package/src/ckb/transaction.ts
CHANGED
package/src/client/client.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Cell,
|
|
3
3
|
CellDep,
|
|
4
|
-
CellDepLike,
|
|
5
4
|
OutPoint,
|
|
6
5
|
OutPointLike,
|
|
7
|
-
Script,
|
|
8
6
|
ScriptLike,
|
|
9
7
|
Transaction,
|
|
10
8
|
TransactionLike,
|
|
@@ -12,11 +10,13 @@ import {
|
|
|
12
10
|
import { Zero } from "../fixedPoint/index.js";
|
|
13
11
|
import { Hex, HexLike, hexFrom } from "../hex/index.js";
|
|
14
12
|
import { Num, NumLike, numFrom, numMax } from "../num/index.js";
|
|
15
|
-
import {
|
|
13
|
+
import { reduceAsync, sleep } from "../utils/index.js";
|
|
16
14
|
import { ClientCache } from "./cache/index.js";
|
|
17
15
|
import { ClientCacheMemory } from "./cache/memory.js";
|
|
18
16
|
import { ClientCollectableSearchKeyLike } from "./clientTypes.advanced.js";
|
|
19
17
|
import {
|
|
18
|
+
CellDepInfo,
|
|
19
|
+
CellDepInfoLike,
|
|
20
20
|
ClientBlock,
|
|
21
21
|
ClientBlockHeader,
|
|
22
22
|
ClientFindCellsResponse,
|
|
@@ -27,62 +27,11 @@ import {
|
|
|
27
27
|
ClientIndexerSearchKeyTransactionLike,
|
|
28
28
|
ClientTransactionResponse,
|
|
29
29
|
ErrorClientWaitTransactionTimeout,
|
|
30
|
+
KnownScript,
|
|
30
31
|
OutputsValidator,
|
|
32
|
+
ScriptInfo,
|
|
31
33
|
} from "./clientTypes.js";
|
|
32
34
|
|
|
33
|
-
/**
|
|
34
|
-
* @public
|
|
35
|
-
*/
|
|
36
|
-
export enum KnownScript {
|
|
37
|
-
NervosDao = "NervosDao",
|
|
38
|
-
Secp256k1Blake160 = "Secp256k1Blake160",
|
|
39
|
-
Secp256k1Multisig = "Secp256k1Multisig",
|
|
40
|
-
AnyoneCanPay = "AnyoneCanPay",
|
|
41
|
-
TypeId = "TypeId",
|
|
42
|
-
XUdt = "XUdt",
|
|
43
|
-
JoyId = "JoyId",
|
|
44
|
-
COTA = "COTA",
|
|
45
|
-
PWLock = "PWLock",
|
|
46
|
-
OmniLock = "OmniLock",
|
|
47
|
-
NostrLock = "NostrLock",
|
|
48
|
-
UniqueType = "UniqueType",
|
|
49
|
-
|
|
50
|
-
// ckb-proxy-locks https://github.com/ckb-ecofund/ckb-proxy-locks
|
|
51
|
-
AlwaysSuccess = "AlwaysSuccess",
|
|
52
|
-
InputTypeProxyLock = "InputTypeProxyLock",
|
|
53
|
-
OutputTypeProxyLock = "OutputTypeProxyLock",
|
|
54
|
-
LockProxyLock = "LockProxyLock",
|
|
55
|
-
SingleUseLock = "SingleUseLock",
|
|
56
|
-
TypeBurnLock = "TypeBurnLock",
|
|
57
|
-
EasyToDiscoverType = "EasyToDiscoverType",
|
|
58
|
-
TimeLock = "TimeLock",
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @public
|
|
63
|
-
*/
|
|
64
|
-
export type CellDepInfoLike = {
|
|
65
|
-
cellDep: CellDepLike;
|
|
66
|
-
type?: ScriptLike | null;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @public
|
|
71
|
-
*/
|
|
72
|
-
export class CellDepInfo {
|
|
73
|
-
constructor(
|
|
74
|
-
public cellDep: CellDep,
|
|
75
|
-
public type?: Script,
|
|
76
|
-
) {}
|
|
77
|
-
|
|
78
|
-
static from(cellDepInfoLike: CellDepInfoLike): CellDepInfo {
|
|
79
|
-
return new CellDepInfo(
|
|
80
|
-
CellDep.from(cellDepInfoLike.cellDep),
|
|
81
|
-
apply(Script.from, cellDepInfoLike.type),
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
35
|
/**
|
|
87
36
|
* @public
|
|
88
37
|
*/
|
|
@@ -96,11 +45,7 @@ export abstract class Client {
|
|
|
96
45
|
abstract get url(): string;
|
|
97
46
|
abstract get addressPrefix(): string;
|
|
98
47
|
|
|
99
|
-
abstract getKnownScript(
|
|
100
|
-
script: KnownScript,
|
|
101
|
-
): Promise<
|
|
102
|
-
Pick<Script, "codeHash" | "hashType"> & { cellDeps: CellDepInfo[] }
|
|
103
|
-
>;
|
|
48
|
+
abstract getKnownScript(script: KnownScript): Promise<ScriptInfo>;
|
|
104
49
|
|
|
105
50
|
abstract getFeeRateStatistics(
|
|
106
51
|
blockRange?: NumLike,
|
|
@@ -600,7 +545,7 @@ export abstract class Client {
|
|
|
600
545
|
} else if (confirmations === 0) {
|
|
601
546
|
return tx;
|
|
602
547
|
} else if (
|
|
603
|
-
(await this.getTipHeader()).number - tx
|
|
548
|
+
(await this.getTipHeader()).number - tx.blockNumber! >=
|
|
604
549
|
confirmations
|
|
605
550
|
) {
|
|
606
551
|
return tx;
|