@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.
Files changed (116) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/bytes/index.d.ts +1 -1
  3. package/dist/bytes/index.d.ts.map +1 -1
  4. package/dist/bytes/index.js +14 -13
  5. package/dist/ckb/transaction.d.ts +6 -6
  6. package/dist/ckb/transaction.d.ts.map +1 -1
  7. package/dist/ckb/transaction.js +1 -0
  8. package/dist/client/client.d.ts +3 -46
  9. package/dist/client/client.d.ts.map +1 -1
  10. package/dist/client/client.js +3 -42
  11. package/dist/client/clientPublicMainnet.advanced.d.ts +2 -5
  12. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  13. package/dist/client/clientPublicMainnet.advanced.js +1 -1
  14. package/dist/client/clientPublicMainnet.d.ts +6 -11
  15. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  16. package/dist/client/clientPublicMainnet.js +2 -5
  17. package/dist/client/clientPublicTestnet.advanced.d.ts +2 -5
  18. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  19. package/dist/client/clientPublicTestnet.advanced.js +1 -1
  20. package/dist/client/clientPublicTestnet.d.ts +6 -11
  21. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  22. package/dist/client/clientPublicTestnet.js +2 -5
  23. package/dist/client/clientTypes.d.ts +60 -1
  24. package/dist/client/clientTypes.d.ts.map +1 -1
  25. package/dist/client/clientTypes.js +53 -1
  26. package/dist/client/jsonRpc/index.d.ts +9 -20
  27. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  28. package/dist/client/jsonRpc/index.js +10 -3
  29. package/dist/client/transports/http.d.ts.map +1 -1
  30. package/dist/client/transports/http.js +2 -0
  31. package/dist/client/transports/webSocket.d.ts.map +1 -1
  32. package/dist/client/transports/webSocket.js +10 -5
  33. package/dist/signer/ckb/verifyJoyId.d.ts.map +1 -1
  34. package/dist/signer/ckb/verifyJoyId.js +1 -0
  35. package/dist/signer/nostr/signerNostr.js +1 -1
  36. package/dist/signer/nostr/verify.d.ts.map +1 -1
  37. package/dist/signer/nostr/verify.js +1 -0
  38. package/dist/utils/index.d.ts +1 -1
  39. package/dist/utils/index.d.ts.map +1 -1
  40. package/dist.commonjs/address/address.advanced.js +3 -3
  41. package/dist.commonjs/bytes/index.d.ts +1 -1
  42. package/dist.commonjs/bytes/index.d.ts.map +1 -1
  43. package/dist.commonjs/bytes/index.js +17 -17
  44. package/dist.commonjs/ckb/molecule.advanced/generated.js +33 -34
  45. package/dist.commonjs/ckb/molecule.advanced/index.js +1 -2
  46. package/dist.commonjs/ckb/script.js +4 -4
  47. package/dist.commonjs/ckb/transaction.d.ts +6 -6
  48. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  49. package/dist.commonjs/ckb/transaction.js +9 -8
  50. package/dist.commonjs/client/cache/memory.advanced.js +5 -6
  51. package/dist.commonjs/client/client.d.ts +3 -46
  52. package/dist.commonjs/client/client.d.ts.map +1 -1
  53. package/dist.commonjs/client/client.js +2 -42
  54. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +2 -5
  55. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  56. package/dist.commonjs/client/clientPublicMainnet.advanced.js +21 -21
  57. package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -11
  58. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  59. package/dist.commonjs/client/clientPublicMainnet.js +2 -5
  60. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +2 -5
  61. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  62. package/dist.commonjs/client/clientPublicTestnet.advanced.js +21 -21
  63. package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -11
  64. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
  65. package/dist.commonjs/client/clientPublicTestnet.js +2 -5
  66. package/dist.commonjs/client/clientTypes.advanced.js +1 -2
  67. package/dist.commonjs/client/clientTypes.d.ts +60 -1
  68. package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
  69. package/dist.commonjs/client/clientTypes.js +55 -1
  70. package/dist.commonjs/client/jsonRpc/index.d.ts +9 -20
  71. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -1
  72. package/dist.commonjs/client/jsonRpc/index.js +9 -2
  73. package/dist.commonjs/client/transports/advanced.js +1 -2
  74. package/dist.commonjs/client/transports/http.d.ts.map +1 -1
  75. package/dist.commonjs/client/transports/http.js +2 -0
  76. package/dist.commonjs/client/transports/webSocket.d.ts.map +1 -1
  77. package/dist.commonjs/client/transports/webSocket.js +10 -5
  78. package/dist.commonjs/fixedPoint/index.js +3 -3
  79. package/dist.commonjs/hasher/hasherCkb.js +3 -3
  80. package/dist.commonjs/hex/index.js +1 -2
  81. package/dist.commonjs/keystore/index.js +2 -3
  82. package/dist.commonjs/num/index.js +10 -11
  83. package/dist.commonjs/signer/btc/verify.js +1 -2
  84. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +2 -3
  85. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts.map +1 -1
  86. package/dist.commonjs/signer/ckb/verifyJoyId.js +2 -2
  87. package/dist.commonjs/signer/evm/verify.js +1 -2
  88. package/dist.commonjs/signer/nostr/signerNostr.js +1 -1
  89. package/dist.commonjs/signer/nostr/verify.d.ts.map +1 -1
  90. package/dist.commonjs/signer/nostr/verify.js +3 -3
  91. package/dist.commonjs/utils/index.d.ts +1 -1
  92. package/dist.commonjs/utils/index.d.ts.map +1 -1
  93. package/dist.commonjs/utils/index.js +4 -5
  94. package/package.json +4 -3
  95. package/src/bytes/index.ts +15 -14
  96. package/src/ckb/transaction.ts +1 -0
  97. package/src/client/client.ts +7 -62
  98. package/src/client/clientPublicMainnet.advanced.ts +329 -333
  99. package/src/client/clientPublicMainnet.ts +3 -11
  100. package/src/client/clientPublicTestnet.advanced.ts +341 -344
  101. package/src/client/clientPublicTestnet.ts +3 -11
  102. package/src/client/clientTypes.ts +87 -0
  103. package/src/client/jsonRpc/index.ts +29 -15
  104. package/src/client/transports/http.ts +2 -0
  105. package/src/client/transports/webSocket.ts +15 -8
  106. package/src/signer/ckb/verifyJoyId.ts +5 -1
  107. package/src/signer/nostr/signerNostr.ts +1 -1
  108. package/src/signer/nostr/verify.ts +2 -1
  109. package/src/utils/index.ts +1 -1
  110. package/dist/fixedPoint/index.test.d.ts +0 -2
  111. package/dist/fixedPoint/index.test.d.ts.map +0 -1
  112. package/dist/fixedPoint/index.test.js +0 -43
  113. package/dist.commonjs/fixedPoint/index.test.d.ts +0 -2
  114. package/dist.commonjs/fixedPoint/index.test.d.ts.map +0 -1
  115. package/dist.commonjs/fixedPoint/index.test.js +0 -45
  116. 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.isWebview = exports.sleep = exports.reduceAsync = exports.apply = void 0;
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.16-alpha.3",
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
  }
@@ -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 (Array.isArray(bytes)) {
102
- if (bytes.some((v) => v < 0 || 0xff < v)) {
103
- throw new Error(`Invalid bytes ${JSON.stringify(bytes)}`);
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
- if (encoding !== undefined) {
109
- return Buffer.from(bytes, encoding);
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 str = bytes.startsWith("0x") ? bytes.slice(2) : bytes;
113
- const paddedStr = str.length % 2 === 0 ? str : `0${str}`;
114
- const data = Buffer.from(paddedStr, "hex");
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 data;
119
+ return new Uint8Array(bytes);
119
120
  }
@@ -1175,6 +1175,7 @@ export class Transaction {
1175
1175
  if (typeof value === "bigint") {
1176
1176
  return numToHex(value);
1177
1177
  }
1178
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
1178
1179
  return value;
1179
1180
  });
1180
1181
  }
@@ -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 { apply, reduceAsync, sleep } from "../utils/index.js";
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!.blockNumber! >=
548
+ (await this.getTipHeader()).number - tx.blockNumber! >=
604
549
  confirmations
605
550
  ) {
606
551
  return tx;