@ckb-ccc/core 0.1.0-alpha.7 → 0.1.1
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 +33 -0
- package/dist/ckb/transactionLumos.d.ts +2 -1
- package/dist/ckb/transactionLumos.d.ts.map +1 -1
- package/dist/client/client.js +1 -1
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +2 -3
- package/dist/signer/btc/verify.d.ts +14 -1
- package/dist/signer/btc/verify.d.ts.map +1 -1
- package/dist/signer/btc/verify.js +22 -1
- package/dist/signer/doge/index.d.ts +5 -0
- package/dist/signer/doge/index.d.ts.map +1 -0
- package/dist/signer/doge/index.js +4 -0
- package/dist/signer/doge/signerDoge.d.ts +52 -0
- package/dist/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist/signer/doge/signerDoge.js +82 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist/signer/doge/signerDogeAddressReadonly.js +45 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist/signer/doge/signerDogePrivateKey.js +68 -0
- package/dist/signer/doge/verify.d.ts +6 -0
- package/dist/signer/doge/verify.d.ts.map +1 -0
- package/dist/signer/doge/verify.js +17 -0
- package/dist/signer/index.d.ts +1 -0
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +1 -0
- package/dist/signer/nostr/index.d.ts +1 -0
- package/dist/signer/nostr/index.d.ts.map +1 -1
- package/dist/signer/nostr/index.js +1 -0
- package/dist/signer/signer/index.d.ts +4 -2
- package/dist/signer/signer/index.d.ts.map +1 -1
- package/dist/signer/signer/index.js +5 -0
- package/dist.commonjs/address/address.advanced.js +23 -28
- package/dist.commonjs/address/advanced.js +1 -17
- package/dist.commonjs/address/index.js +11 -15
- package/dist.commonjs/advanced.js +2 -31
- package/dist.commonjs/advancedBarrel.js +5 -21
- package/dist.commonjs/barrel.js +12 -41
- package/dist.commonjs/bytes/advanced.js +1 -2
- package/dist.commonjs/bytes/index.js +7 -12
- package/dist.commonjs/ckb/advanced.js +3 -32
- package/dist.commonjs/ckb/index.js +3 -19
- package/dist.commonjs/ckb/molecule.advanced/generated.js +64 -131
- package/dist.commonjs/ckb/molecule.advanced/index.js +2 -19
- package/dist.commonjs/ckb/script.advanced.js +3 -6
- package/dist.commonjs/ckb/script.js +23 -53
- package/dist.commonjs/ckb/transaction.advanced.js +3 -6
- package/dist.commonjs/ckb/transaction.js +122 -163
- package/dist.commonjs/ckb/transactionLumos.d.ts +2 -1
- package/dist.commonjs/ckb/transactionLumos.d.ts.map +1 -1
- package/dist.commonjs/ckb/transactionLumos.js +1 -2
- package/dist.commonjs/client/advanced.js +6 -22
- package/dist.commonjs/client/cache/advanced.js +1 -17
- package/dist.commonjs/client/cache/cache.js +3 -7
- package/dist.commonjs/client/cache/index.js +2 -18
- package/dist.commonjs/client/cache/memory.advanced.js +21 -28
- package/dist.commonjs/client/cache/memory.js +19 -23
- package/dist.commonjs/client/client.js +22 -26
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +22 -25
- package/dist.commonjs/client/clientPublicMainnet.js +8 -15
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +22 -25
- package/dist.commonjs/client/clientPublicTestnet.js +8 -15
- package/dist.commonjs/client/clientTypes.advanced.js +3 -6
- package/dist.commonjs/client/clientTypes.js +29 -43
- package/dist.commonjs/client/index.js +6 -22
- package/dist.commonjs/client/jsonRpc/advanced.js +2 -18
- package/dist.commonjs/client/jsonRpc/index.js +37 -41
- package/dist.commonjs/client/jsonRpc/transformers.js +57 -61
- package/dist.commonjs/client/jsonRpc/types.js +1 -2
- package/dist.commonjs/client/transports/advanced.js +8 -25
- package/dist.commonjs/client/transports/http.js +1 -5
- package/dist.commonjs/client/transports/transport.js +1 -2
- package/dist.commonjs/client/transports/webSocket.js +3 -10
- package/dist.commonjs/fixedPoint/index.js +4 -9
- package/dist.commonjs/hasher/advanced.js +1 -4
- package/dist.commonjs/hasher/hasher.js +1 -2
- package/dist.commonjs/hasher/hasherCkb.js +14 -20
- package/dist.commonjs/hasher/hasherKeecak256.js +7 -11
- package/dist.commonjs/hasher/index.js +3 -19
- package/dist.commonjs/hex/index.js +3 -6
- package/dist.commonjs/index.js +2 -31
- package/dist.commonjs/keystore/index.js +21 -25
- package/dist.commonjs/molecule/codec.js +48 -63
- package/dist.commonjs/molecule/index.js +2 -18
- package/dist.commonjs/molecule/predefined.js +77 -103
- package/dist.commonjs/num/index.js +17 -29
- package/dist.commonjs/signer/btc/index.js +3 -19
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/signerBtc.js +20 -25
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +4 -8
- package/dist.commonjs/signer/btc/verify.d.ts +14 -1
- package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/verify.js +29 -11
- package/dist.commonjs/signer/ckb/index.js +5 -21
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +16 -20
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +20 -24
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +8 -12
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +12 -16
- package/dist.commonjs/signer/ckb/verifyJoyId.js +5 -8
- package/dist.commonjs/signer/doge/index.d.ts +5 -0
- package/dist.commonjs/signer/doge/index.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/index.js +4 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDoge.js +82 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +45 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.js +68 -0
- package/dist.commonjs/signer/doge/verify.d.ts +6 -0
- package/dist.commonjs/signer/doge/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/verify.js +17 -0
- package/dist.commonjs/signer/dummy/alwaysError.js +2 -6
- package/dist.commonjs/signer/dummy/dummy.js +3 -7
- package/dist.commonjs/signer/dummy/index.js +3 -19
- package/dist.commonjs/signer/dummy/openLink.js +2 -6
- package/dist.commonjs/signer/evm/index.js +3 -19
- package/dist.commonjs/signer/evm/signerEvm.js +31 -35
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +4 -8
- package/dist.commonjs/signer/evm/verify.js +4 -7
- package/dist.commonjs/signer/index.d.ts +1 -0
- package/dist.commonjs/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/index.js +7 -22
- package/dist.commonjs/signer/nostr/index.d.ts +1 -0
- package/dist.commonjs/signer/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/signer/nostr/index.js +2 -17
- package/dist.commonjs/signer/nostr/signerNostr.js +21 -25
- package/dist.commonjs/signer/nostr/verify.js +12 -16
- package/dist.commonjs/signer/signer/index.d.ts +4 -2
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/signer/index.js +22 -23
- package/dist.commonjs/utils/index.js +6 -12
- package/package.json +8 -1
- package/src/ckb/transactionLumos.ts +2 -1
- package/src/client/client.ts +1 -1
- package/src/signer/btc/signerBtc.ts +2 -3
- package/src/signer/btc/verify.ts +31 -2
- package/src/signer/doge/index.ts +4 -0
- package/src/signer/doge/signerDoge.ts +116 -0
- package/src/signer/doge/signerDogeAddressReadonly.ts +52 -0
- package/src/signer/doge/signerDogePrivateKey.ts +97 -0
- package/src/signer/doge/verify.ts +38 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/nostr/index.ts +1 -0
- package/src/signer/signer/index.ts +9 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CellDepLike, CellOutputLike,
|
|
1
|
+
import { CellDepLike, CellOutputLike, OutPointLike } from "../ckb/index.js";
|
|
2
|
+
import { HexLike } from "../hex/index.js";
|
|
2
3
|
export interface LumosTransactionSkeletonType {
|
|
3
4
|
cellDeps: {
|
|
4
5
|
toArray(): CellDepLike[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionLumos.d.ts","sourceRoot":"","sources":["../../src/ckb/transactionLumos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"transactionLumos.d.ts","sourceRoot":"","sources":["../../src/ckb/transactionLumos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE;QACR,OAAO,IAAI,WAAW,EAAE,CAAC;KAC1B,CAAC;IACF,UAAU,EAAE;QACV,OAAO,IAAI,OAAO,EAAE,CAAC;KACtB,CAAC;IACF,MAAM,EAAE;QACN,OAAO,IAAI;YACT,QAAQ,CAAC,EAAE,YAAY,CAAC;YACxB,UAAU,EAAE,cAAc,CAAC;YAC3B,IAAI,EAAE,OAAO,CAAC;SACf,EAAE,CAAC;KACL,CAAC;IACF,WAAW,EAAE;QACX,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;KAC7C,CAAC;IACF,OAAO,EAAE;QACP,OAAO,IAAI;YAAE,UAAU,EAAE,cAAc,CAAC;YAAC,IAAI,EAAE,OAAO,CAAA;SAAE,EAAE,CAAC;KAC5D,CAAC;IACF,SAAS,EAAE;QACT,OAAO,IAAI,OAAO,EAAE,CAAC;KACtB,CAAC;CACH"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cache/advanced.js"), exports);
|
|
18
|
-
__exportStar(require("./clientPublicMainnet.advanced.js"), exports);
|
|
19
|
-
__exportStar(require("./clientPublicTestnet.advanced.js"), exports);
|
|
20
|
-
__exportStar(require("./clientTypes.advanced.js"), exports);
|
|
21
|
-
__exportStar(require("./jsonRpc/advanced.js"), exports);
|
|
22
|
-
__exportStar(require("./transports/advanced.js"), exports);
|
|
1
|
+
export * from "./cache/advanced.js";
|
|
2
|
+
export * from "./clientPublicMainnet.advanced.js";
|
|
3
|
+
export * from "./clientPublicTestnet.advanced.js";
|
|
4
|
+
export * from "./clientTypes.advanced.js";
|
|
5
|
+
export * from "./jsonRpc/advanced.js";
|
|
6
|
+
export * from "./transports/advanced.js";
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./memory.advanced.js"), exports);
|
|
1
|
+
export * from "./memory.advanced.js";
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ClientCache = void 0;
|
|
4
|
-
const index_js_1 = require("../../ckb/index.js");
|
|
5
|
-
class ClientCache {
|
|
1
|
+
import { Transaction, } from "../../ckb/index.js";
|
|
2
|
+
export class ClientCache {
|
|
6
3
|
async markTransactions(...transactionLike) {
|
|
7
4
|
await Promise.all([
|
|
8
5
|
this.recordTransactions(...transactionLike),
|
|
9
6
|
...transactionLike.flat().map((transactionLike) => {
|
|
10
|
-
const tx =
|
|
7
|
+
const tx = Transaction.from(transactionLike);
|
|
11
8
|
const txHash = tx.hash();
|
|
12
9
|
return Promise.all([
|
|
13
10
|
...tx.inputs.map((i) => this.markUnusable(i.previousOutput)),
|
|
@@ -44,4 +41,3 @@ class ClientCache {
|
|
|
44
41
|
*/
|
|
45
42
|
async recordCells(..._cells) { }
|
|
46
43
|
}
|
|
47
|
-
exports.ClientCache = ClientCache;
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cache.js"), exports);
|
|
18
|
-
__exportStar(require("./memory.js"), exports);
|
|
1
|
+
export * from "./cache.js";
|
|
2
|
+
export * from "./memory.js";
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const index_js_1 = require("../../bytes/index.js");
|
|
9
|
-
const index_js_2 = require("../../ckb/index.js");
|
|
10
|
-
const index_js_3 = require("../../hex/index.js");
|
|
11
|
-
const index_js_4 = require("../../num/index.js");
|
|
12
|
-
const clientTypes_advanced_js_1 = require("../clientTypes.advanced.js");
|
|
13
|
-
const clientTypes_js_1 = require("../clientTypes.js");
|
|
14
|
-
function filterData(dataLike, filterLike, filterMode) {
|
|
1
|
+
import { bytesFrom } from "../../bytes/index.js";
|
|
2
|
+
import { Cell, Script } from "../../ckb/index.js";
|
|
3
|
+
import { hexFrom } from "../../hex/index.js";
|
|
4
|
+
import { numFrom } from "../../num/index.js";
|
|
5
|
+
import { clientSearchKeyRangeFrom, } from "../clientTypes.advanced.js";
|
|
6
|
+
import { ClientIndexerSearchKey } from "../clientTypes.js";
|
|
7
|
+
export function filterData(dataLike, filterLike, filterMode) {
|
|
15
8
|
if (!filterLike) {
|
|
16
9
|
return true;
|
|
17
10
|
}
|
|
18
|
-
const data =
|
|
19
|
-
const filter =
|
|
11
|
+
const data = hexFrom(dataLike);
|
|
12
|
+
const filter = hexFrom(filterLike);
|
|
20
13
|
if ((filterMode === "exact" && data !== filter) ||
|
|
21
14
|
(filterMode === "prefix" && !data.startsWith(filter)) ||
|
|
22
15
|
(filterMode === "partial" && data.search(filter) === -1)) {
|
|
@@ -24,30 +17,30 @@ function filterData(dataLike, filterLike, filterMode) {
|
|
|
24
17
|
}
|
|
25
18
|
return true;
|
|
26
19
|
}
|
|
27
|
-
function filterScript(valueLike, filterLike, filterMode) {
|
|
20
|
+
export function filterScript(valueLike, filterLike, filterMode) {
|
|
28
21
|
if (!filterLike) {
|
|
29
22
|
return true;
|
|
30
23
|
}
|
|
31
24
|
if (!valueLike) {
|
|
32
25
|
return false;
|
|
33
26
|
}
|
|
34
|
-
const value =
|
|
35
|
-
const filter =
|
|
27
|
+
const value = Script.from(valueLike);
|
|
28
|
+
const filter = Script.from(filterLike);
|
|
36
29
|
if (value.codeHash !== filter.codeHash ||
|
|
37
30
|
value.hashType !== filter.hashType) {
|
|
38
31
|
return false;
|
|
39
32
|
}
|
|
40
33
|
return filterData(value.args, filter?.args, filterMode);
|
|
41
34
|
}
|
|
42
|
-
function filterNumByRange(lengthLike, range) {
|
|
35
|
+
export function filterNumByRange(lengthLike, range) {
|
|
43
36
|
if (!range) {
|
|
44
37
|
return true;
|
|
45
38
|
}
|
|
46
|
-
const length =
|
|
47
|
-
const [lower, upper] =
|
|
39
|
+
const length = numFrom(lengthLike);
|
|
40
|
+
const [lower, upper] = clientSearchKeyRangeFrom(range);
|
|
48
41
|
return lower <= length && length < upper;
|
|
49
42
|
}
|
|
50
|
-
function filterScriptByLenRange(valueLike, scriptLenRange) {
|
|
43
|
+
export function filterScriptByLenRange(valueLike, scriptLenRange) {
|
|
51
44
|
if (!scriptLenRange) {
|
|
52
45
|
return true;
|
|
53
46
|
}
|
|
@@ -55,13 +48,13 @@ function filterScriptByLenRange(valueLike, scriptLenRange) {
|
|
|
55
48
|
if (!valueLike) {
|
|
56
49
|
return 0;
|
|
57
50
|
}
|
|
58
|
-
return
|
|
51
|
+
return bytesFrom(Script.from(valueLike).args).length + 33;
|
|
59
52
|
})();
|
|
60
53
|
return filterNumByRange(len, scriptLenRange);
|
|
61
54
|
}
|
|
62
|
-
function filterCell(searchKeyLike, cellLike) {
|
|
63
|
-
const key =
|
|
64
|
-
const cell =
|
|
55
|
+
export function filterCell(searchKeyLike, cellLike) {
|
|
56
|
+
const key = ClientIndexerSearchKey.from(searchKeyLike);
|
|
57
|
+
const cell = Cell.from(cellLike);
|
|
65
58
|
if (key.scriptType === "lock") {
|
|
66
59
|
if (!filterScript(cell.cellOutput.lock, key.script, key.scriptSearchMode) ||
|
|
67
60
|
!filterScript(cell.cellOutput.type, key.filter?.script, "prefix") ||
|
|
@@ -77,7 +70,7 @@ function filterCell(searchKeyLike, cellLike) {
|
|
|
77
70
|
}
|
|
78
71
|
}
|
|
79
72
|
if (!filterData(cell.outputData, key.filter?.outputData, key.filter?.outputDataSearchMode ?? "prefix") ||
|
|
80
|
-
!filterNumByRange(
|
|
73
|
+
!filterNumByRange(bytesFrom(cell.outputData).length, key.filter?.outputDataLenRange)) {
|
|
81
74
|
return false;
|
|
82
75
|
}
|
|
83
76
|
if (!filterNumByRange(cell.cellOutput.capacity, key.filter?.outputCapacityRange)) {
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const cache_js_1 = require("./cache.js");
|
|
7
|
-
const memory_advanced_js_1 = require("./memory.advanced.js");
|
|
8
|
-
class ClientCacheMemory extends cache_js_1.ClientCache {
|
|
1
|
+
import { Cell, OutPoint, Transaction, } from "../../ckb/index.js";
|
|
2
|
+
import { hexFrom } from "../../hex/index.js";
|
|
3
|
+
import { ClientCache } from "./cache.js";
|
|
4
|
+
import { filterCell } from "./memory.advanced.js";
|
|
5
|
+
export class ClientCacheMemory extends ClientCache {
|
|
9
6
|
constructor() {
|
|
10
7
|
super(...arguments);
|
|
11
8
|
/**
|
|
@@ -19,15 +16,15 @@ class ClientCacheMemory extends cache_js_1.ClientCache {
|
|
|
19
16
|
}
|
|
20
17
|
async markUsable(...cellLikes) {
|
|
21
18
|
cellLikes.flat().forEach((cellLike) => {
|
|
22
|
-
const cell =
|
|
23
|
-
const outPointStr =
|
|
19
|
+
const cell = Cell.from(cellLike).clone();
|
|
20
|
+
const outPointStr = hexFrom(cell.outPoint.toBytes());
|
|
24
21
|
this.cells.set(outPointStr, [true, cell]);
|
|
25
22
|
});
|
|
26
23
|
}
|
|
27
24
|
async markUnusable(...outPointLikes) {
|
|
28
25
|
outPointLikes.flat().forEach((outPointLike) => {
|
|
29
|
-
const outPoint =
|
|
30
|
-
const outPointStr =
|
|
26
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
27
|
+
const outPointStr = hexFrom(outPoint.toBytes());
|
|
31
28
|
const existed = this.cells.get(outPointStr);
|
|
32
29
|
if (existed) {
|
|
33
30
|
existed[0] = false;
|
|
@@ -46,37 +43,37 @@ class ClientCacheMemory extends cache_js_1.ClientCache {
|
|
|
46
43
|
if (!isLive) {
|
|
47
44
|
continue;
|
|
48
45
|
}
|
|
49
|
-
if (!
|
|
46
|
+
if (!filterCell(keyLike, cell)) {
|
|
50
47
|
continue;
|
|
51
48
|
}
|
|
52
49
|
yield cell.clone();
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
52
|
async getCell(outPointLike) {
|
|
56
|
-
const outPoint =
|
|
57
|
-
const cell = this.cells.get(
|
|
53
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
54
|
+
const cell = this.cells.get(hexFrom(outPoint.toBytes()))?.[1];
|
|
58
55
|
if (cell && cell.cellOutput && cell.outputData) {
|
|
59
|
-
return
|
|
56
|
+
return Cell.from(cell.clone());
|
|
60
57
|
}
|
|
61
58
|
}
|
|
62
59
|
async isUnusable(outPointLike) {
|
|
63
|
-
const outPoint =
|
|
64
|
-
return !(this.cells.get(
|
|
60
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
61
|
+
return !(this.cells.get(hexFrom(outPoint.toBytes()))?.[0] ?? true);
|
|
65
62
|
}
|
|
66
63
|
async recordTransactions(...transactions) {
|
|
67
64
|
transactions.flat().map((txLike) => {
|
|
68
|
-
const tx =
|
|
65
|
+
const tx = Transaction.from(txLike);
|
|
69
66
|
this.knownTransactions.set(tx.hash(), tx);
|
|
70
67
|
});
|
|
71
68
|
}
|
|
72
69
|
async getTransaction(txHashLike) {
|
|
73
|
-
const txHash =
|
|
70
|
+
const txHash = hexFrom(txHashLike);
|
|
74
71
|
return this.knownTransactions.get(txHash)?.clone();
|
|
75
72
|
}
|
|
76
73
|
async recordCells(...cells) {
|
|
77
74
|
cells.flat().map((cellLike) => {
|
|
78
|
-
const cell =
|
|
79
|
-
const outPointStr =
|
|
75
|
+
const cell = Cell.from(cellLike);
|
|
76
|
+
const outPointStr = hexFrom(cell.outPoint.toBytes());
|
|
80
77
|
if (this.cells.get(outPointStr)) {
|
|
81
78
|
return;
|
|
82
79
|
}
|
|
@@ -84,4 +81,3 @@ class ClientCacheMemory extends cache_js_1.ClientCache {
|
|
|
84
81
|
});
|
|
85
82
|
}
|
|
86
83
|
}
|
|
87
|
-
exports.ClientCacheMemory = ClientCacheMemory;
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const index_js_5 = require("../utils/index.js");
|
|
9
|
-
const memory_js_1 = require("./cache/memory.js");
|
|
10
|
-
const clientTypes_js_1 = require("./clientTypes.js");
|
|
1
|
+
import { Cell, CellDep, OutPoint, Transaction, } from "../ckb/index.js";
|
|
2
|
+
import { Zero } from "../fixedPoint/index.js";
|
|
3
|
+
import { hexFrom } from "../hex/index.js";
|
|
4
|
+
import { numFrom, numMax } from "../num/index.js";
|
|
5
|
+
import { reduceAsync, sleep } from "../utils/index.js";
|
|
6
|
+
import { ClientCacheMemory } from "./cache/memory.js";
|
|
7
|
+
import { CellDepInfo, ClientIndexerSearchKey, ErrorClientWaitTransactionTimeout, } from "./clientTypes.js";
|
|
11
8
|
/**
|
|
12
9
|
* @public
|
|
13
10
|
*/
|
|
14
|
-
class Client {
|
|
11
|
+
export class Client {
|
|
15
12
|
constructor(config) {
|
|
16
|
-
this.cache = config?.cache ?? new
|
|
13
|
+
this.cache = config?.cache ?? new ClientCacheMemory();
|
|
17
14
|
}
|
|
18
15
|
async getFeeRate(blockRange) {
|
|
19
|
-
return
|
|
16
|
+
return numMax((await this.getFeeRateStatistics(blockRange)).median, 1000);
|
|
20
17
|
}
|
|
21
18
|
async getCell(outPointLike) {
|
|
22
|
-
const outPoint =
|
|
19
|
+
const outPoint = OutPoint.from(outPointLike);
|
|
23
20
|
const cached = await this.cache.getCell(outPoint);
|
|
24
21
|
if (cached) {
|
|
25
22
|
return cached;
|
|
@@ -28,11 +25,11 @@ class Client {
|
|
|
28
25
|
if (!transaction) {
|
|
29
26
|
return;
|
|
30
27
|
}
|
|
31
|
-
const index = Number(
|
|
28
|
+
const index = Number(numFrom(outPoint.index));
|
|
32
29
|
if (index >= transaction.transaction.outputs.length) {
|
|
33
30
|
return;
|
|
34
31
|
}
|
|
35
|
-
const cell =
|
|
32
|
+
const cell = Cell.from({
|
|
36
33
|
outPoint,
|
|
37
34
|
cellOutput: transaction.transaction.outputs[index],
|
|
38
35
|
outputData: transaction.transaction.outputsData[index] ?? "0x",
|
|
@@ -72,7 +69,7 @@ class Client {
|
|
|
72
69
|
* @returns A async generator for yielding cells.
|
|
73
70
|
*/
|
|
74
71
|
async *findCells(keyLike, order, limit = 10) {
|
|
75
|
-
const key =
|
|
72
|
+
const key = ClientIndexerSearchKey.from(keyLike);
|
|
76
73
|
const foundedOutPoints = [];
|
|
77
74
|
for await (const cell of this.cache.findCells(key)) {
|
|
78
75
|
foundedOutPoints.push(cell.outPoint);
|
|
@@ -112,7 +109,7 @@ class Client {
|
|
|
112
109
|
}
|
|
113
110
|
async getCellDeps(...cellDepsInfoLike) {
|
|
114
111
|
return Promise.all(cellDepsInfoLike.flat().map(async (infoLike) => {
|
|
115
|
-
const { cellDep, type } =
|
|
112
|
+
const { cellDep, type } = CellDepInfo.from(infoLike);
|
|
116
113
|
if (type === undefined) {
|
|
117
114
|
return cellDep;
|
|
118
115
|
}
|
|
@@ -120,7 +117,7 @@ class Client {
|
|
|
120
117
|
if (!found) {
|
|
121
118
|
return cellDep;
|
|
122
119
|
}
|
|
123
|
-
return
|
|
120
|
+
return CellDep.from({
|
|
124
121
|
outPoint: found.outPoint,
|
|
125
122
|
depType: cellDep.depType,
|
|
126
123
|
});
|
|
@@ -170,17 +167,17 @@ class Client {
|
|
|
170
167
|
});
|
|
171
168
|
}
|
|
172
169
|
async getBalance(locks) {
|
|
173
|
-
return
|
|
170
|
+
return reduceAsync(locks, async (acc, lock) => acc + (await this.getBalanceSingle(lock)), Zero);
|
|
174
171
|
}
|
|
175
172
|
async sendTransaction(transaction, validator) {
|
|
176
|
-
const tx =
|
|
173
|
+
const tx = Transaction.from(transaction);
|
|
177
174
|
const txHash = await this.sendTransactionNoCache(tx, validator);
|
|
178
175
|
await this.cache.recordTransactions(tx);
|
|
179
176
|
await this.cache.markTransactions(tx);
|
|
180
177
|
return txHash;
|
|
181
178
|
}
|
|
182
179
|
async getTransaction(txHashLike) {
|
|
183
|
-
const txHash =
|
|
180
|
+
const txHash = hexFrom(txHashLike);
|
|
184
181
|
const res = await this.getTransactionNoCache(txHash);
|
|
185
182
|
if (res?.transaction) {
|
|
186
183
|
return res;
|
|
@@ -200,7 +197,7 @@ class Client {
|
|
|
200
197
|
transaction: tx,
|
|
201
198
|
};
|
|
202
199
|
}
|
|
203
|
-
async waitTransaction(txHash, confirmations = 0, timeout =
|
|
200
|
+
async waitTransaction(txHash, confirmations = 0, timeout = 60000, interval = 2000) {
|
|
204
201
|
const startTime = Date.now();
|
|
205
202
|
let tx;
|
|
206
203
|
const getTx = async () => {
|
|
@@ -227,10 +224,9 @@ class Client {
|
|
|
227
224
|
return tx;
|
|
228
225
|
}
|
|
229
226
|
if (Date.now() - startTime + interval >= timeout) {
|
|
230
|
-
throw new
|
|
227
|
+
throw new ErrorClientWaitTransactionTimeout();
|
|
231
228
|
}
|
|
232
|
-
await
|
|
229
|
+
await sleep(interval);
|
|
233
230
|
}
|
|
234
231
|
}
|
|
235
232
|
}
|
|
236
|
-
exports.Client = Client;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
const clientTypes_js_1 = require("./clientTypes.js");
|
|
5
|
-
exports.MAINNET_SCRIPTS = Object.freeze({
|
|
6
|
-
[clientTypes_js_1.KnownScript.NervosDao]: {
|
|
1
|
+
import { KnownScript } from "./clientTypes.js";
|
|
2
|
+
export const MAINNET_SCRIPTS = Object.freeze({
|
|
3
|
+
[KnownScript.NervosDao]: {
|
|
7
4
|
codeHash: "0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e",
|
|
8
5
|
hashType: "type",
|
|
9
6
|
cellDeps: [
|
|
@@ -18,7 +15,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
18
15
|
},
|
|
19
16
|
],
|
|
20
17
|
},
|
|
21
|
-
[
|
|
18
|
+
[KnownScript.Secp256k1Blake160]: {
|
|
22
19
|
codeHash: "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
|
|
23
20
|
hashType: "type",
|
|
24
21
|
cellDeps: [
|
|
@@ -33,7 +30,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
33
30
|
},
|
|
34
31
|
],
|
|
35
32
|
},
|
|
36
|
-
[
|
|
33
|
+
[KnownScript.Secp256k1Multisig]: {
|
|
37
34
|
codeHash: "0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8",
|
|
38
35
|
hashType: "type",
|
|
39
36
|
cellDeps: [
|
|
@@ -48,7 +45,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
48
45
|
},
|
|
49
46
|
],
|
|
50
47
|
},
|
|
51
|
-
[
|
|
48
|
+
[KnownScript.AnyoneCanPay]: {
|
|
52
49
|
codeHash: "0xd369597ff47f29fbc0d47d2e3775370d1250b85140c670e4718af712983a2354",
|
|
53
50
|
hashType: "type",
|
|
54
51
|
cellDeps: [
|
|
@@ -63,12 +60,12 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
63
60
|
},
|
|
64
61
|
],
|
|
65
62
|
},
|
|
66
|
-
[
|
|
63
|
+
[KnownScript.TypeId]: {
|
|
67
64
|
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
68
65
|
hashType: "type",
|
|
69
66
|
cellDeps: [],
|
|
70
67
|
},
|
|
71
|
-
[
|
|
68
|
+
[KnownScript.XUdt]: {
|
|
72
69
|
codeHash: "0x50bd8d6680b8b9cf98b73f3c08faf8b2a21914311954118ad6609be6e78a1b95",
|
|
73
70
|
hashType: "data1",
|
|
74
71
|
cellDeps: [
|
|
@@ -83,7 +80,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
83
80
|
},
|
|
84
81
|
],
|
|
85
82
|
},
|
|
86
|
-
[
|
|
83
|
+
[KnownScript.JoyId]: {
|
|
87
84
|
codeHash: "0xd00c84f0ec8fd441c38bc3f87a371f547190f2fcff88e642bc5bf54b9e318323",
|
|
88
85
|
hashType: "type",
|
|
89
86
|
cellDeps: [
|
|
@@ -98,7 +95,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
98
95
|
},
|
|
99
96
|
],
|
|
100
97
|
},
|
|
101
|
-
[
|
|
98
|
+
[KnownScript.COTA]: {
|
|
102
99
|
codeHash: "0x1122a4fb54697cf2e6e3a96c9d80fd398a936559b90954c6e88eb7ba0cf652df",
|
|
103
100
|
hashType: "type",
|
|
104
101
|
cellDeps: [
|
|
@@ -113,7 +110,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
113
110
|
},
|
|
114
111
|
],
|
|
115
112
|
},
|
|
116
|
-
[
|
|
113
|
+
[KnownScript.PWLock]: {
|
|
117
114
|
codeHash: "0xbf43c3602455798c1a61a596e0d95278864c552fafe231c063b3fabf97a8febc",
|
|
118
115
|
hashType: "type",
|
|
119
116
|
cellDeps: [
|
|
@@ -142,7 +139,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
142
139
|
},
|
|
143
140
|
],
|
|
144
141
|
},
|
|
145
|
-
[
|
|
142
|
+
[KnownScript.OmniLock]: {
|
|
146
143
|
codeHash: "0x9b819793a64463aed77c615d6cb226eea5487ccfc0783043a587254cda2b6f26",
|
|
147
144
|
hashType: "type",
|
|
148
145
|
cellDeps: [
|
|
@@ -171,7 +168,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
171
168
|
},
|
|
172
169
|
],
|
|
173
170
|
},
|
|
174
|
-
[
|
|
171
|
+
[KnownScript.NostrLock]: {
|
|
175
172
|
codeHash: "0x641a89ad2f77721b803cd50d01351c1f308444072d5fa20088567196c0574c68",
|
|
176
173
|
hashType: "type",
|
|
177
174
|
cellDeps: [
|
|
@@ -191,7 +188,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
191
188
|
},
|
|
192
189
|
],
|
|
193
190
|
},
|
|
194
|
-
[
|
|
191
|
+
[KnownScript.UniqueType]: {
|
|
195
192
|
codeHash: "0x2c8c11c985da60b0a330c61a85507416d6382c130ba67f0c47ab071e00aec628",
|
|
196
193
|
hashType: "data1",
|
|
197
194
|
cellDeps: [
|
|
@@ -206,7 +203,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
206
203
|
},
|
|
207
204
|
],
|
|
208
205
|
},
|
|
209
|
-
[
|
|
206
|
+
[KnownScript.AlwaysSuccess]: {
|
|
210
207
|
codeHash: "0x3b521cc4b552f109d092d8cc468a8048acb53c5952dbe769d2b2f9cf6e47f7f1",
|
|
211
208
|
hashType: "data1",
|
|
212
209
|
cellDeps: [
|
|
@@ -221,7 +218,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
221
218
|
},
|
|
222
219
|
],
|
|
223
220
|
},
|
|
224
|
-
[
|
|
221
|
+
[KnownScript.InputTypeProxyLock]: {
|
|
225
222
|
codeHash: "0x5123908965c711b0ffd8aec642f1ede329649bda1ebdca6bd24124d3796f768a",
|
|
226
223
|
hashType: "data1",
|
|
227
224
|
cellDeps: [
|
|
@@ -236,7 +233,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
236
233
|
},
|
|
237
234
|
],
|
|
238
235
|
},
|
|
239
|
-
[
|
|
236
|
+
[KnownScript.OutputTypeProxyLock]: {
|
|
240
237
|
codeHash: "0x2df53b592db3ae3685b7787adcfef0332a611edb83ca3feca435809964c3aff2",
|
|
241
238
|
hashType: "data1",
|
|
242
239
|
cellDeps: [
|
|
@@ -251,7 +248,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
251
248
|
},
|
|
252
249
|
],
|
|
253
250
|
},
|
|
254
|
-
[
|
|
251
|
+
[KnownScript.LockProxyLock]: {
|
|
255
252
|
codeHash: "0x5d41e32e224c15f152b7e6529100ebeac83b162f5f692a5365774dad2c1a1d02",
|
|
256
253
|
hashType: "data1",
|
|
257
254
|
cellDeps: [
|
|
@@ -266,7 +263,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
266
263
|
},
|
|
267
264
|
],
|
|
268
265
|
},
|
|
269
|
-
[
|
|
266
|
+
[KnownScript.SingleUseLock]: {
|
|
270
267
|
codeHash: "0x8290467a512e5b9a6b816469b0edabba1f4ac474e28ffdd604c2a7c76446bbaf",
|
|
271
268
|
hashType: "data1",
|
|
272
269
|
cellDeps: [
|
|
@@ -281,7 +278,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
281
278
|
},
|
|
282
279
|
],
|
|
283
280
|
},
|
|
284
|
-
[
|
|
281
|
+
[KnownScript.TypeBurnLock]: {
|
|
285
282
|
codeHash: "0xff78bae0abf17d7a404c0be0f9ad9c9185b3f88dcc60403453d5ba8e1f22f53a",
|
|
286
283
|
hashType: "data1",
|
|
287
284
|
cellDeps: [
|
|
@@ -296,7 +293,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
296
293
|
},
|
|
297
294
|
],
|
|
298
295
|
},
|
|
299
|
-
[
|
|
296
|
+
[KnownScript.EasyToDiscoverType]: {
|
|
300
297
|
codeHash: "0xaba4430cc7110d699007095430a1faa72973edf2322ddbfd4d1d219cacf237af",
|
|
301
298
|
hashType: "data1",
|
|
302
299
|
cellDeps: [
|
|
@@ -311,7 +308,7 @@ exports.MAINNET_SCRIPTS = Object.freeze({
|
|
|
311
308
|
},
|
|
312
309
|
],
|
|
313
310
|
},
|
|
314
|
-
[
|
|
311
|
+
[KnownScript.TimeLock]: {
|
|
315
312
|
codeHash: "0x6fac4b2e89360a1e692efcddcb3a28656d8446549fb83da6d896db8b714f4451",
|
|
316
313
|
hashType: "data1",
|
|
317
314
|
cellDeps: [
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ClientPublicMainnet = void 0;
|
|
7
|
-
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
8
|
-
const clientPublicMainnet_advanced_js_1 = require("./clientPublicMainnet.advanced.js");
|
|
9
|
-
const clientTypes_js_1 = require("./clientTypes.js");
|
|
10
|
-
const index_js_1 = require("./jsonRpc/index.js");
|
|
1
|
+
import WebSocket from "isomorphic-ws";
|
|
2
|
+
import { MAINNET_SCRIPTS } from "./clientPublicMainnet.advanced.js";
|
|
3
|
+
import { ScriptInfo } from "./clientTypes.js";
|
|
4
|
+
import { ClientJsonRpc } from "./jsonRpc/index.js";
|
|
11
5
|
/**
|
|
12
6
|
* @public
|
|
13
7
|
*/
|
|
14
|
-
class ClientPublicMainnet extends
|
|
8
|
+
export class ClientPublicMainnet extends ClientJsonRpc {
|
|
15
9
|
constructor(config) {
|
|
16
10
|
super(config?.url ??
|
|
17
|
-
(typeof
|
|
11
|
+
(typeof WebSocket !== "undefined"
|
|
18
12
|
? "wss://mainnet.ckb.dev/ws"
|
|
19
13
|
: "https://mainnet.ckb.dev/"), config);
|
|
20
14
|
this.config = config;
|
|
21
15
|
}
|
|
22
16
|
get scripts() {
|
|
23
|
-
return this.config?.scripts ??
|
|
17
|
+
return this.config?.scripts ?? MAINNET_SCRIPTS;
|
|
24
18
|
}
|
|
25
19
|
get addressPrefix() {
|
|
26
20
|
return "ckb";
|
|
@@ -30,7 +24,6 @@ class ClientPublicMainnet extends index_js_1.ClientJsonRpc {
|
|
|
30
24
|
if (!found) {
|
|
31
25
|
throw new Error(`No script information was found for ${script} on ${this.addressPrefix}`);
|
|
32
26
|
}
|
|
33
|
-
return
|
|
27
|
+
return ScriptInfo.from(found);
|
|
34
28
|
}
|
|
35
29
|
}
|
|
36
|
-
exports.ClientPublicMainnet = ClientPublicMainnet;
|