@ckb-ccc/core 0.0.5-alpha.2 → 0.0.6-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/ckb/transaction.d.ts +17 -6
  2. package/dist/ckb/transaction.d.ts.map +1 -1
  3. package/dist/ckb/transaction.js +39 -15
  4. package/dist/client/client.d.ts +7 -6
  5. package/dist/client/client.d.ts.map +1 -1
  6. package/dist/client/client.js +9 -7
  7. package/dist/client/clientPublicMainnet.advanced.d.ts +1 -1
  8. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  9. package/dist/client/clientPublicMainnet.advanced.js +1 -0
  10. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  11. package/dist/client/clientPublicMainnet.js +5 -1
  12. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  13. package/dist/client/clientPublicTestnet.advanced.js +4 -0
  14. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  15. package/dist/signer/btc/signerBtc.js +4 -2
  16. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +0 -6
  17. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  18. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +0 -8
  19. package/dist/signer/btc/verify.d.ts.map +1 -1
  20. package/dist/signer/btc/verify.js +5 -2
  21. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +0 -6
  22. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  23. package/dist/signer/ckb/signerCkbScriptReadonly.js +0 -8
  24. package/dist/signer/dummy/alwaysError.d.ts +9 -0
  25. package/dist/signer/dummy/alwaysError.d.ts.map +1 -0
  26. package/dist/signer/dummy/alwaysError.js +10 -0
  27. package/dist/signer/dummy/dummy.d.ts +12 -0
  28. package/dist/signer/dummy/dummy.d.ts.map +1 -0
  29. package/dist/signer/dummy/dummy.js +19 -0
  30. package/dist/signer/dummy/index.d.ts +4 -0
  31. package/dist/signer/dummy/index.d.ts.map +1 -0
  32. package/dist/signer/dummy/index.js +3 -0
  33. package/dist/signer/dummy/openLink.d.ts +9 -0
  34. package/dist/signer/dummy/openLink.d.ts.map +1 -0
  35. package/dist/signer/dummy/openLink.js +10 -0
  36. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  37. package/dist/signer/evm/signerEvm.js +3 -3
  38. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +0 -6
  39. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  40. package/dist/signer/evm/signerEvmAddressReadonly.js +0 -8
  41. package/dist/signer/index.d.ts +2 -0
  42. package/dist/signer/index.d.ts.map +1 -1
  43. package/dist/signer/index.js +2 -0
  44. package/dist/signer/nostr/index.d.ts +2 -0
  45. package/dist/signer/nostr/index.d.ts.map +1 -0
  46. package/dist/signer/nostr/index.js +1 -0
  47. package/dist/signer/nostr/signerNostr.d.ts +66 -0
  48. package/dist/signer/nostr/signerNostr.d.ts.map +1 -0
  49. package/dist/signer/nostr/signerNostr.js +84 -0
  50. package/dist/signer/nostr/verify.d.ts +5 -0
  51. package/dist/signer/nostr/verify.d.ts.map +1 -0
  52. package/dist/signer/nostr/verify.js +48 -0
  53. package/dist/signer/{signer.d.ts → signer/index.d.ts} +14 -19
  54. package/dist/signer/signer/index.d.ts.map +1 -0
  55. package/dist/signer/{signer.js → signer/index.js} +14 -7
  56. package/dist/utils/index.d.ts +60 -0
  57. package/dist/utils/index.d.ts.map +1 -1
  58. package/dist/utils/index.js +20 -0
  59. package/dist.commonjs/ckb/transaction.d.ts +17 -6
  60. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  61. package/dist.commonjs/ckb/transaction.js +39 -15
  62. package/dist.commonjs/client/client.d.ts +7 -6
  63. package/dist.commonjs/client/client.d.ts.map +1 -1
  64. package/dist.commonjs/client/client.js +9 -7
  65. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +1 -1
  66. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  67. package/dist.commonjs/client/clientPublicMainnet.advanced.js +1 -0
  68. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  69. package/dist.commonjs/client/clientPublicMainnet.js +5 -1
  70. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  71. package/dist.commonjs/client/clientPublicTestnet.advanced.js +4 -0
  72. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  73. package/dist.commonjs/signer/btc/signerBtc.js +4 -2
  74. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +0 -6
  75. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  76. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +0 -8
  77. package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
  78. package/dist.commonjs/signer/btc/verify.js +5 -2
  79. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +0 -6
  80. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  81. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +0 -8
  82. package/dist.commonjs/signer/dummy/alwaysError.d.ts +9 -0
  83. package/dist.commonjs/signer/dummy/alwaysError.d.ts.map +1 -0
  84. package/dist.commonjs/signer/dummy/alwaysError.js +14 -0
  85. package/dist.commonjs/signer/dummy/dummy.d.ts +12 -0
  86. package/dist.commonjs/signer/dummy/dummy.d.ts.map +1 -0
  87. package/dist.commonjs/signer/dummy/dummy.js +23 -0
  88. package/dist.commonjs/signer/dummy/index.d.ts +4 -0
  89. package/dist.commonjs/signer/dummy/index.d.ts.map +1 -0
  90. package/dist.commonjs/signer/dummy/index.js +19 -0
  91. package/dist.commonjs/signer/dummy/openLink.d.ts +9 -0
  92. package/dist.commonjs/signer/dummy/openLink.d.ts.map +1 -0
  93. package/dist.commonjs/signer/dummy/openLink.js +14 -0
  94. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  95. package/dist.commonjs/signer/evm/signerEvm.js +3 -3
  96. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +0 -6
  97. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  98. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +0 -8
  99. package/dist.commonjs/signer/index.d.ts +2 -0
  100. package/dist.commonjs/signer/index.d.ts.map +1 -1
  101. package/dist.commonjs/signer/index.js +2 -0
  102. package/dist.commonjs/signer/nostr/index.d.ts +2 -0
  103. package/dist.commonjs/signer/nostr/index.d.ts.map +1 -0
  104. package/dist.commonjs/signer/nostr/index.js +17 -0
  105. package/dist.commonjs/signer/nostr/signerNostr.d.ts +66 -0
  106. package/dist.commonjs/signer/nostr/signerNostr.d.ts.map +1 -0
  107. package/dist.commonjs/signer/nostr/signerNostr.js +88 -0
  108. package/dist.commonjs/signer/nostr/verify.d.ts +5 -0
  109. package/dist.commonjs/signer/nostr/verify.d.ts.map +1 -0
  110. package/dist.commonjs/signer/nostr/verify.js +53 -0
  111. package/dist.commonjs/signer/{signer.d.ts → signer/index.d.ts} +14 -19
  112. package/dist.commonjs/signer/signer/index.d.ts.map +1 -0
  113. package/dist.commonjs/signer/{signer.js → signer/index.js} +14 -7
  114. package/dist.commonjs/utils/index.d.ts +60 -0
  115. package/dist.commonjs/utils/index.d.ts.map +1 -1
  116. package/dist.commonjs/utils/index.js +23 -1
  117. package/package.json +4 -3
  118. package/src/ckb/transaction.ts +50 -18
  119. package/src/client/client.ts +12 -10
  120. package/src/client/clientPublicMainnet.advanced.ts +2 -1
  121. package/src/client/clientPublicMainnet.ts +7 -1
  122. package/src/client/clientPublicTestnet.advanced.ts +5 -0
  123. package/src/signer/btc/signerBtc.ts +4 -7
  124. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +0 -9
  125. package/src/signer/btc/verify.ts +6 -3
  126. package/src/signer/ckb/signerCkbScriptReadonly.ts +0 -9
  127. package/src/signer/dummy/alwaysError.ts +17 -0
  128. package/src/signer/dummy/dummy.ts +28 -0
  129. package/src/signer/dummy/index.ts +3 -0
  130. package/src/signer/dummy/openLink.ts +17 -0
  131. package/src/signer/evm/signerEvm.ts +7 -9
  132. package/src/signer/evm/signerEvmAddressReadonly.ts +0 -9
  133. package/src/signer/index.ts +2 -0
  134. package/src/signer/nostr/index.ts +1 -0
  135. package/src/signer/nostr/signerNostr.ts +134 -0
  136. package/src/signer/nostr/verify.ts +63 -0
  137. package/src/signer/{signer.ts → signer/index.ts} +24 -20
  138. package/src/utils/index.ts +108 -0
  139. package/dist/signer/signer.d.ts.map +0 -1
  140. package/dist.commonjs/signer/signer.d.ts.map +0 -1
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignerNostr = void 0;
4
+ const bech32_1 = require("bech32");
5
+ const address_1 = require("../../address");
6
+ const bytes_1 = require("../../bytes");
7
+ const ckb_1 = require("../../ckb");
8
+ const client_1 = require("../../client");
9
+ const hasher_1 = require("../../hasher");
10
+ const hex_1 = require("../../hex");
11
+ const signer_1 = require("../signer");
12
+ const verify_1 = require("./verify");
13
+ class SignerNostr extends signer_1.Signer {
14
+ get type() {
15
+ return signer_1.SignerType.Nostr;
16
+ }
17
+ get signType() {
18
+ return signer_1.SignerSignType.NostrEvent;
19
+ }
20
+ /**
21
+ * Sign a message.
22
+ *
23
+ * @returns A promise that resolves to the signature.
24
+ */
25
+ async signMessageRaw(message) {
26
+ return (0, hex_1.hexFrom)((await this.signNostrEvent((0, verify_1.buildNostrEventFromMessage)(message))).sig);
27
+ }
28
+ /**
29
+ * Gets the internal address, which is the EVM account in this case.
30
+ *
31
+ * @returns A promise that resolves to a string representing the internal address.
32
+ */
33
+ async getInternalAddress() {
34
+ return bech32_1.bech32.encode("npub", bech32_1.bech32.toWords((0, bytes_1.bytesFrom)(await this.getNostrPublicKey())));
35
+ }
36
+ /**
37
+ * Gets an array of Address objects representing the known script addresses for the signer.
38
+ *
39
+ * @returns A promise that resolves to an array of Address objects.
40
+ */
41
+ async getAddressObjs() {
42
+ const publicKey = await this.getNostrPublicKey();
43
+ return [
44
+ await address_1.Address.fromKnownScript(client_1.KnownScript.NostrLock, (0, hex_1.hexFrom)((0, bytes_1.bytesConcat)([0x00], (0, hasher_1.ckbHash)(publicKey).slice(0, 42))), this.client),
45
+ ];
46
+ }
47
+ /**
48
+ * prepare a transaction before signing.
49
+ *
50
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
51
+ * @returns A promise that resolves to the prepared Transaction object.
52
+ */
53
+ async prepareTransaction(txLike) {
54
+ const tx = ckb_1.Transaction.from(txLike);
55
+ const { script } = await this.getRecommendedAddressObj();
56
+ await tx.prepareSighashAllWitness(script, 572, this.client);
57
+ return tx;
58
+ }
59
+ /**
60
+ * Signs a transaction without modifying it.
61
+ *
62
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
63
+ * @returns A promise that resolves to a signed Transaction object.
64
+ */
65
+ async signOnlyTransaction(txLike) {
66
+ let tx = ckb_1.Transaction.from(txLike);
67
+ const { script } = await this.getRecommendedAddressObj();
68
+ const info = await tx.getSignHashInfo(script, this.client);
69
+ if (!info) {
70
+ return tx;
71
+ }
72
+ const signedEvent = (0, bytes_1.bytesFrom)(JSON.stringify(await this.signNostrEvent({
73
+ pubkey: (await this.getNostrPublicKey()).slice(2),
74
+ tags: [[SignerNostr.CKB_SIG_HASH_ALL_TAG, info.message.slice(2)]],
75
+ created_at: Math.floor(Date.now() / 1000),
76
+ kind: SignerNostr.CKB_UNLOCK_EVENT_KIND,
77
+ content: SignerNostr.CKB_UNLOCK_EVENT_CONTENT,
78
+ })), "utf8");
79
+ const witness = ckb_1.WitnessArgs.fromBytes(tx.witnesses[info.position]);
80
+ witness.lock = (0, hex_1.hexFrom)(signedEvent);
81
+ tx.setWitnessArgsAt(info.position, witness);
82
+ return tx;
83
+ }
84
+ }
85
+ exports.SignerNostr = SignerNostr;
86
+ SignerNostr.CKB_SIG_HASH_ALL_TAG = "ckb_sighash_all";
87
+ SignerNostr.CKB_UNLOCK_EVENT_KIND = 23334;
88
+ SignerNostr.CKB_UNLOCK_EVENT_CONTENT = "Signing a CKB transaction\n\nIMPORTANT: Please verify the integrity and authenticity of connected Nostr client before signing this message\n";
@@ -0,0 +1,5 @@
1
+ import { BytesLike } from "../../bytes";
2
+ import { NostrEvent } from "./signerNostr";
3
+ export declare function buildNostrEventFromMessage(message: string | BytesLike): NostrEvent;
4
+ export declare function verifyMessageNostrEvent(message: string | BytesLike, signature: string, address: string): boolean;
5
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/signer/nostr/verify.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAa,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,UAAU,CA2BZ;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAoBT"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyMessageNostrEvent = exports.buildNostrEventFromMessage = void 0;
4
+ const secp256k1_1 = require("@noble/curves/secp256k1");
5
+ const sha256_1 = require("@noble/hashes/sha256");
6
+ const bech32_1 = require("bech32");
7
+ const bytes_1 = require("../../bytes");
8
+ const hex_1 = require("../../hex");
9
+ function buildNostrEventFromMessage(message) {
10
+ if (typeof message === "string") {
11
+ try {
12
+ const event = JSON.parse(message);
13
+ if (typeof event === "object" &&
14
+ typeof event.created_at === "number" &&
15
+ typeof event.kind === "number" &&
16
+ typeof event.content === "string" &&
17
+ Array.isArray(event.args) &&
18
+ event.args.every((tag) => Array.isArray(tag) &&
19
+ tag.every((v) => typeof v === "string"))) {
20
+ return event;
21
+ }
22
+ }
23
+ catch (_) { }
24
+ }
25
+ return {
26
+ kind: 23335,
27
+ created_at: 0,
28
+ content: typeof message === "string" ? message : (0, hex_1.hexFrom)(message),
29
+ tags: [],
30
+ };
31
+ }
32
+ exports.buildNostrEventFromMessage = buildNostrEventFromMessage;
33
+ function verifyMessageNostrEvent(message, signature, address) {
34
+ const { words } = bech32_1.bech32.decode(address);
35
+ const publicKey = (0, hex_1.hexFrom)(bech32_1.bech32.fromWords(words)).slice(2);
36
+ const event = buildNostrEventFromMessage(message);
37
+ const serialized = JSON.stringify([
38
+ 0,
39
+ publicKey,
40
+ event.created_at,
41
+ event.kind,
42
+ event.tags,
43
+ event.content,
44
+ ]);
45
+ const eventHash = (0, hex_1.hexFrom)((0, sha256_1.sha256)((0, bytes_1.bytesFrom)(serialized, "utf8")));
46
+ try {
47
+ return secp256k1_1.schnorr.verify(signature.slice(2), eventHash.slice(2), publicKey);
48
+ }
49
+ catch (_) {
50
+ return false;
51
+ }
52
+ }
53
+ exports.verifyMessageNostrEvent = verifyMessageNostrEvent;
@@ -1,14 +1,15 @@
1
- import { Address } from "../address";
2
- import { BytesLike } from "../bytes";
3
- import { Transaction, TransactionLike } from "../ckb";
4
- import { Client } from "../client";
5
- import { Hex } from "../hex";
6
- import { Num } from "../num";
1
+ import { Address } from "../../address";
2
+ import { BytesLike } from "../../bytes";
3
+ import { Transaction, TransactionLike } from "../../ckb";
4
+ import { Client } from "../../client";
5
+ import { Hex } from "../../hex";
6
+ import { Num } from "../../num";
7
7
  export declare enum SignerSignType {
8
8
  Unknown = "Unknown",
9
9
  BtcEcdsa = "BtcEcdsa",
10
10
  EvmPersonal = "EvmPersonal",
11
- JoyId = "JoyId"
11
+ JoyId = "JoyId",
12
+ NostrEvent = "NostrEvent"
12
13
  }
13
14
  /**
14
15
  * An enumeration of signer display types in wallet.
@@ -16,7 +17,8 @@ export declare enum SignerSignType {
16
17
  export declare enum SignerType {
17
18
  EVM = "EVM",
18
19
  BTC = "BTC",
19
- CKB = "CKB"
20
+ CKB = "CKB",
21
+ Nostr = "Nostr"
20
22
  }
21
23
  export declare class Signature {
22
24
  signature: string;
@@ -36,23 +38,16 @@ export declare abstract class Signer {
36
38
  get client(): Client;
37
39
  static verifyMessage(message: string | BytesLike, signature: Signature): Promise<boolean>;
38
40
  /**
39
- * Construct a new signer with the client replaced.
40
- *
41
- * @returns A promise that resolves the new Signer.
41
+ * Replace the current client.
42
+ * returns false if the new client is invalid for this signer.
42
43
  */
43
- abstract replaceClient(client: Client): Promise<Signer>;
44
+ replaceClient(client: Client): Promise<boolean>;
44
45
  /**
45
46
  * Connects to the signer.
46
47
  *
47
48
  * @returns A promise that resolves when the connection is complete.
48
49
  */
49
50
  abstract connect(): Promise<void>;
50
- /**
51
- * Disconnects to the signer.
52
- *
53
- * @returns A promise that resolves when disconnected.
54
- */
55
- disconnect(): Promise<void>;
56
51
  /**
57
52
  * Check if the signer is connected.
58
53
  *
@@ -183,4 +178,4 @@ export type Wallet = {
183
178
  name: string;
184
179
  icon: string;
185
180
  };
186
- //# sourceMappingURL=signer.d.ts.map
181
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/signer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAMhC,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,Q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,15 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SignerInfo = exports.Signer = exports.Signature = exports.SignerType = exports.SignerSignType = void 0;
4
- const btc_1 = require("./btc");
5
- const verifyJoyId_1 = require("./ckb/verifyJoyId");
6
- const verify_1 = require("./evm/verify");
4
+ const btc_1 = require("../btc");
5
+ const verifyJoyId_1 = require("../ckb/verifyJoyId");
6
+ const verify_1 = require("../evm/verify");
7
+ const verify_2 = require("../nostr/verify");
7
8
  var SignerSignType;
8
9
  (function (SignerSignType) {
9
10
  SignerSignType["Unknown"] = "Unknown";
10
11
  SignerSignType["BtcEcdsa"] = "BtcEcdsa";
11
12
  SignerSignType["EvmPersonal"] = "EvmPersonal";
12
13
  SignerSignType["JoyId"] = "JoyId";
14
+ SignerSignType["NostrEvent"] = "NostrEvent";
13
15
  })(SignerSignType || (exports.SignerSignType = SignerSignType = {}));
14
16
  /**
15
17
  * An enumeration of signer display types in wallet.
@@ -19,6 +21,7 @@ var SignerType;
19
21
  SignerType["EVM"] = "EVM";
20
22
  SignerType["BTC"] = "BTC";
21
23
  SignerType["CKB"] = "CKB";
24
+ SignerType["Nostr"] = "Nostr";
22
25
  })(SignerType || (exports.SignerType = SignerType = {}));
23
26
  class Signature {
24
27
  constructor(signature, identity, signType) {
@@ -47,16 +50,20 @@ class Signer {
47
50
  return (0, btc_1.verifyMessageBtcEcdsa)(message, signature.signature, signature.identity);
48
51
  case SignerSignType.JoyId:
49
52
  return (0, verifyJoyId_1.verifyMessageJoyId)(message, signature.signature, signature.identity);
53
+ case SignerSignType.NostrEvent:
54
+ return (0, verify_2.verifyMessageNostrEvent)(message, signature.signature, signature.identity);
50
55
  case SignerSignType.Unknown:
51
56
  throw new Error("Unknown signer sign type");
52
57
  }
53
58
  }
54
59
  /**
55
- * Disconnects to the signer.
56
- *
57
- * @returns A promise that resolves when disconnected.
60
+ * Replace the current client.
61
+ * returns false if the new client is invalid for this signer.
58
62
  */
59
- async disconnect() { }
63
+ async replaceClient(client) {
64
+ this.client_ = client;
65
+ return true;
66
+ }
60
67
  /**
61
68
  * Gets the identity for verifying signature, usually it's address
62
69
  *
@@ -1,7 +1,67 @@
1
+ /**
2
+ * A type safe way to apply a transformer on a value if it's not empty.
3
+ *
4
+ * @param transformer - The transformer.
5
+ * @param value - The value to be transformed.
6
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
7
+ */
1
8
  export declare function apply<T, R>(transformer: (val: T) => R, value: undefined): undefined;
9
+ /**
10
+ * A type safe way to apply a transformer on a value if it's not empty.
11
+ *
12
+ * @param transformer - The transformer.
13
+ * @param value - The value to be transformed.
14
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
15
+ */
2
16
  export declare function apply<T, R>(transformer: (val: T) => R, value: null): null;
17
+ /**
18
+ * A type safe way to apply a transformer on a value if it's not empty.
19
+ *
20
+ * @param transformer - The transformer.
21
+ * @param value - The value to be transformed.
22
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
23
+ */
3
24
  export declare function apply<T, R>(transformer: (val: T) => R, value: T): R;
25
+ /**
26
+ * A type safe way to apply a transformer on a value if it's not empty.
27
+ *
28
+ * @param transformer - The transformer.
29
+ * @param value - The value to be transformed.
30
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
31
+ */
4
32
  export declare function apply<T, R>(transformer: (val: T) => R, value: T | undefined): R | undefined;
33
+ /**
34
+ * A type safe way to apply a transformer on a value if it's not empty.
35
+ *
36
+ * @param transformer - The transformer.
37
+ * @param value - The value to be transformed.
38
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
39
+ */
5
40
  export declare function apply<T, R>(transformer: (val: T) => R, value: T | null): R | null;
41
+ /**
42
+ * A type safe way to apply a transformer on a value if it's not empty.
43
+ *
44
+ * @param transformer - The transformer.
45
+ * @param value - The value to be transformed.
46
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
47
+ */
6
48
  export declare function apply<T, R>(transformer: (val: T) => R, value: undefined | null): undefined | null;
49
+ /**
50
+ * Similar to Array.reduce, but the accumulator can returns Promise.
51
+ *
52
+ * @param values - The array to be reduced.
53
+ * @param accumulator - A callback to be called for each value. If it returns null, the previous result will be kept.
54
+ * @returns The accumulated result.
55
+ */
56
+ export declare function reduceAsync<T, V>(values: T[], accumulator: (a: T, b: T) => Promise<T | undefined | null | void> | T | undefined | null | void): Promise<T>;
57
+ /**
58
+ * Similar to Array.reduce, but the accumulator can returns Promise.
59
+ *
60
+ * @param values - The array to be reduced.
61
+ * @param accumulator - A callback to be called for each value. If it returns null, the previous result will be kept.
62
+ * @param init - The initial value.
63
+ * @returns The accumulated result.
64
+ */
65
+ export declare function reduceAsync<T, V>(values: V[], accumulator: (a: T, b: V) => Promise<T | undefined | null | void> | T | undefined | null | void, init: T): Promise<T>;
66
+ export declare function isWebview(userAgent: string): boolean;
7
67
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GACf,SAAS,CAAC;AACb,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;AAC3E,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;AACrE,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,CAAC,GAAG,SAAS,GACnB,CAAC,GAAG,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C,GAAG,IAAI,CAAC;AACZ;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACxB,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,EAC1B,KAAK,EAAE,SAAS,GAAG,IAAI,GACtB,SAAS,GAAG,IAAI,CAAC;AAmBpB;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC,EACpC,MAAM,EAAE,CAAC,EAAE,EACX,WAAW,EAAE,CACX,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,KACD,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,GACtE,OAAO,CAAC,CAAC,CAAC,CAAC;AACd;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC,EACpC,MAAM,EAAE,CAAC,EAAE,EACX,WAAW,EAAE,CACX,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,KACD,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,EACvE,IAAI,EAAE,CAAC,GACN,OAAO,CAAC,CAAC,CAAC,CAAC;AA0Bd,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEpD"}
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.apply = void 0;
3
+ exports.isWebview = exports.reduceAsync = exports.apply = void 0;
4
+ /**
5
+ * A type safe way to apply a transformer on a value if it's not empty.
6
+ *
7
+ * @param transformer - The transformer.
8
+ * @param value - The value to be transformed.
9
+ * @returns If the value is empty, it remains its type. Otherwise it will be transformed.
10
+ */
4
11
  function apply(transformer, value) {
5
12
  if (value == null) {
6
13
  return value;
@@ -8,3 +15,18 @@ function apply(transformer, value) {
8
15
  return transformer(value);
9
16
  }
10
17
  exports.apply = apply;
18
+ async function reduceAsync(values, accumulator, init) {
19
+ if (init === undefined) {
20
+ if (values.length === 0) {
21
+ throw new TypeError("Reduce of empty array with no initial value");
22
+ }
23
+ init = values[0];
24
+ values = values.slice(1);
25
+ }
26
+ return values.reduce((current, b) => current.then((v) => Promise.resolve(accumulator(v, b)).then((r) => r ?? v)), Promise.resolve(init));
27
+ }
28
+ exports.reduceAsync = reduceAsync;
29
+ function isWebview(userAgent) {
30
+ return /webview|wv|ip((?!.*Safari)|(?=.*like Safari))/i.test(userAgent);
31
+ }
32
+ exports.isWebview = isWebview;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/core",
3
- "version": "0.0.5-alpha.2",
3
+ "version": "0.0.6-alpha.0",
4
4
  "description": "Common Chains Connector Core",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -58,14 +58,15 @@
58
58
  "dependencies": {
59
59
  "@ckb-lumos/helpers": "^0.22.2",
60
60
  "@joyid/ckb": "^0.0.11",
61
+ "@noble/curves": "^1.4.2",
61
62
  "@noble/hashes": "^1.4.0",
62
- "@unisat/wallet-utils": "^1.0.0",
63
63
  "abort-controller": "^3.0.0",
64
64
  "bech32": "^2.0.0",
65
+ "bitcoinjs-message": "^2.2.0",
65
66
  "blake2b": "^2.1.4",
66
67
  "buffer": "^6.0.3",
67
68
  "cross-fetch": "^4.0.0",
68
69
  "ethers": "^6.13.1"
69
70
  },
70
- "gitHead": "abbcbe8e25dc561e0a134d3906f40bb49b8a035f"
71
+ "gitHead": "2cbb4f450ed88e773a353a13ad006dbe6208f67f"
71
72
  }
@@ -384,24 +384,23 @@ export class CellInput {
384
384
  * @returns The completed instance.
385
385
  * @example
386
386
  * ```typescript
387
- * if (!cellInput.cellOutput) {
388
- * await cellInput.completeExtraInfos();
389
- * }
387
+ * await cellInput.completeExtraInfos();
390
388
  * ```
391
389
  */
392
390
 
393
- async completeExtraInfos(client: Client): Promise<CellInput> {
391
+ async completeExtraInfos(client: Client): Promise<void> {
394
392
  if (this.cellOutput && this.outputData && this.blockNumber) {
395
- return this;
393
+ return;
396
394
  }
397
395
 
398
396
  const cell = await client.getCell(this.previousOutput);
399
- if (cell) {
400
- this.cellOutput = cell.cellOutput;
401
- this.outputData = cell.outputData;
402
- this.blockNumber = cell.blockNumber;
397
+ if (!cell) {
398
+ return;
403
399
  }
404
- return this;
400
+
401
+ this.cellOutput = cell.cellOutput;
402
+ this.outputData = cell.outputData;
403
+ this.blockNumber = cell.blockNumber;
405
404
  }
406
405
 
407
406
  /**
@@ -867,8 +866,9 @@ export class Transaction {
867
866
  hasher.update(this.hash());
868
867
 
869
868
  for (let i = 0; i < this.witnesses.length; i += 1) {
870
- if (this.inputs[i]) {
871
- const input = await this.inputs[i].completeExtraInfos(client);
869
+ const input = this.inputs[i];
870
+ if (input) {
871
+ await input.completeExtraInfos(client);
872
872
 
873
873
  if (!input.cellOutput) {
874
874
  throw Error("Unable to resolve inputs info");
@@ -919,7 +919,40 @@ export class Transaction {
919
919
  const script = Script.from(scriptLike);
920
920
 
921
921
  for (let i = 0; i < this.inputs.length; i += 1) {
922
- const input = await this.inputs[i].completeExtraInfos(client);
922
+ const input = this.inputs[i];
923
+ await input.completeExtraInfos(client);
924
+
925
+ if (!input.cellOutput) {
926
+ throw Error("Unable to resolve inputs info");
927
+ }
928
+
929
+ if (script.eq(input.cellOutput.lock)) {
930
+ return i;
931
+ }
932
+ }
933
+ }
934
+
935
+ /**
936
+ * Find the last occurrence of a input with the specified lock
937
+ *
938
+ * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
939
+ * @param client - The client for complete extra infos in the transaction.
940
+ * @returns A promise that resolves to the prepared transaction
941
+ *
942
+ * @example
943
+ * ```typescript
944
+ * const index = await tx.findLastInputIndexByLock(scriptLike, client);
945
+ * ```
946
+ */
947
+ async findLastInputIndexByLock(
948
+ scriptLike: ScriptLike,
949
+ client: Client,
950
+ ): Promise<number | undefined> {
951
+ const script = Script.from(scriptLike);
952
+
953
+ for (let i = this.inputs.length - 1; i >= 0; i -= 1) {
954
+ const input = this.inputs[i];
955
+ await input.completeExtraInfos(client);
923
956
 
924
957
  if (!input.cellOutput) {
925
958
  throw Error("Unable to resolve inputs info");
@@ -961,7 +994,7 @@ export class Transaction {
961
994
  * await tx.setWitnessArgsAt(0, witnessArgs);
962
995
  * ```
963
996
  */
964
- setWitnessArgsAt(index: number, witness: WitnessArgs): Transaction {
997
+ setWitnessArgsAt(index: number, witness: WitnessArgs): void {
965
998
  if (this.witnesses.length < index) {
966
999
  this.witnesses.push(
967
1000
  ...Array.from(
@@ -972,7 +1005,6 @@ export class Transaction {
972
1005
  }
973
1006
 
974
1007
  this.witnesses[index] = hexFrom(witness.toBytes());
975
- return this;
976
1008
  }
977
1009
 
978
1010
  /**
@@ -992,14 +1024,14 @@ export class Transaction {
992
1024
  scriptLike: ScriptLike,
993
1025
  lockLen: number,
994
1026
  client: Client,
995
- ): Promise<Transaction> {
1027
+ ): Promise<void> {
996
1028
  const position = await this.findInputIndexByLock(scriptLike, client);
997
1029
  if (position === undefined) {
998
- return this;
1030
+ return;
999
1031
  }
1000
1032
 
1001
1033
  const witness = this.getWitnessArgsAt(position) ?? WitnessArgs.from({});
1002
1034
  witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
1003
- return this.setWitnessArgsAt(position, witness);
1035
+ this.setWitnessArgsAt(position, witness);
1004
1036
  }
1005
1037
  }
@@ -8,6 +8,7 @@ import {
8
8
  import { Zero } from "../fixedPoint";
9
9
  import { Hex, HexLike } from "../hex";
10
10
  import { Num, NumLike, numFrom } from "../num";
11
+ import { reduceAsync } from "../utils";
11
12
  import {
12
13
  ClientFindCellsResponse,
13
14
  ClientIndexerSearchKeyLike,
@@ -16,12 +17,13 @@ import {
16
17
  } from "./clientTypes";
17
18
 
18
19
  export enum KnownScript {
19
- Secp256k1Blake160,
20
- Secp256k1Multisig,
21
- AnyoneCanPay,
22
- JoyId,
23
- COTA,
24
- OmniLock,
20
+ Secp256k1Blake160 = "Secp256k1Blake160",
21
+ Secp256k1Multisig = "Secp256k1Multisig",
22
+ AnyoneCanPay = "AnyoneCanPay",
23
+ JoyId = "JoyId",
24
+ COTA = "COTA",
25
+ OmniLock = "OmniLock",
26
+ NostrLock = "NostrLock",
25
27
  }
26
28
 
27
29
  export abstract class Client {
@@ -121,10 +123,10 @@ export abstract class Client {
121
123
  }
122
124
 
123
125
  async getBalance(locks: ScriptLike[]): Promise<Num> {
124
- return locks.reduce(
125
- (res: Promise<Num>, lock) =>
126
- this.getBalanceSingle(lock).then((a) => res.then((b) => a + b)),
127
- Promise.resolve(Zero),
126
+ return reduceAsync(
127
+ locks,
128
+ async (acc, lock) => acc + (await this.getBalanceSingle(lock)),
129
+ Zero,
128
130
  );
129
131
  }
130
132
  }
@@ -3,7 +3,7 @@ import { KnownScript } from "./client";
3
3
 
4
4
  export const MAINNET_SCRIPTS: Record<
5
5
  KnownScript,
6
- Pick<Script, "codeHash" | "hashType">
6
+ Pick<Script, "codeHash" | "hashType"> | undefined
7
7
  > = {
8
8
  [KnownScript.Secp256k1Blake160]: {
9
9
  codeHash:
@@ -35,4 +35,5 @@ export const MAINNET_SCRIPTS: Record<
35
35
  "0x9b819793a64463aed77c615d6cb226eea5487ccfc0783043a587254cda2b6f26",
36
36
  hashType: "type",
37
37
  },
38
+ [KnownScript.NostrLock]: undefined,
38
39
  };
@@ -15,6 +15,12 @@ export class ClientPublicMainnet extends ClientJsonRpc {
15
15
  async getKnownScript(
16
16
  script: KnownScript,
17
17
  ): Promise<Pick<Script, "codeHash" | "hashType">> {
18
- return { ...MAINNET_SCRIPTS[script] };
18
+ const found = MAINNET_SCRIPTS[script];
19
+ if (!found) {
20
+ throw new Error(
21
+ `No script information was found for ${script} on ${this.addressPrefix}`,
22
+ );
23
+ }
24
+ return { ...found };
19
25
  }
20
26
  }
@@ -35,4 +35,9 @@ export const TESTNET_SCRIPTS: Record<
35
35
  "0xf329effd1c475a2978453c8600e1eaf0bc2087ee093c3ee64cc96ec6847752cb",
36
36
  hashType: "type",
37
37
  },
38
+ [KnownScript.NostrLock]: {
39
+ codeHash:
40
+ "0x6ae5ee0cb887b2df5a9a18137315b9bdc55be8d52637b2de0624092d5f0c91d5",
41
+ hashType: "type",
42
+ },
38
43
  };
@@ -79,12 +79,10 @@ export abstract class SignerBtc extends Signer {
79
79
  * @returns A promise that resolves to the prepared Transaction object.
80
80
  */
81
81
  async prepareTransaction(txLike: TransactionLike): Promise<Transaction> {
82
+ const tx = Transaction.from(txLike);
82
83
  const { script } = await this.getRecommendedAddressObj();
83
- return Transaction.from(txLike).prepareSighashAllWitness(
84
- script,
85
- 85,
86
- this.client,
87
- );
84
+ await tx.prepareSighashAllWitness(script, 85, this.client);
85
+ return tx;
88
86
  }
89
87
 
90
88
  /**
@@ -121,8 +119,7 @@ export abstract class SignerBtc extends Signer {
121
119
  ),
122
120
  );
123
121
 
124
- tx.witnesses[info.position] = hexFrom(witness.toBytes());
125
-
122
+ tx.setWitnessArgsAt(info.position, witness);
126
123
  return tx;
127
124
  }
128
125
  }
@@ -26,15 +26,6 @@ export class SignerBtcPublicKeyReadonly extends SignerBtc {
26
26
  this.publicKey = hexFrom(publicKey);
27
27
  }
28
28
 
29
- /**
30
- * Construct a new signer with the client replaced.
31
- *
32
- * @returns A promise that resolves the new Signer.
33
- */
34
- async replaceClient(client: Client): Promise<SignerBtcPublicKeyReadonly> {
35
- return new SignerBtcPublicKeyReadonly(client, this.account, this.publicKey);
36
- }
37
-
38
29
  /**
39
30
  * Connects to the client. This implementation does nothing as the class is read-only.
40
31
  *