@ckb-ccc/core 0.0.5-alpha.8 → 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 (124) 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 +0 -1
  25. package/dist/signer/dummy/alwaysError.d.ts.map +1 -1
  26. package/dist/signer/dummy/alwaysError.js +0 -3
  27. package/dist/signer/dummy/openLink.d.ts +0 -1
  28. package/dist/signer/dummy/openLink.d.ts.map +1 -1
  29. package/dist/signer/dummy/openLink.js +0 -3
  30. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  31. package/dist/signer/evm/signerEvm.js +3 -3
  32. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +0 -6
  33. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  34. package/dist/signer/evm/signerEvmAddressReadonly.js +0 -8
  35. package/dist/signer/index.d.ts +1 -0
  36. package/dist/signer/index.d.ts.map +1 -1
  37. package/dist/signer/index.js +1 -0
  38. package/dist/signer/nostr/index.d.ts +2 -0
  39. package/dist/signer/nostr/index.d.ts.map +1 -0
  40. package/dist/signer/nostr/index.js +1 -0
  41. package/dist/signer/nostr/signerNostr.d.ts +66 -0
  42. package/dist/signer/nostr/signerNostr.d.ts.map +1 -0
  43. package/dist/signer/nostr/signerNostr.js +84 -0
  44. package/dist/signer/nostr/verify.d.ts +5 -0
  45. package/dist/signer/nostr/verify.d.ts.map +1 -0
  46. package/dist/signer/nostr/verify.js +48 -0
  47. package/dist/signer/signer/index.d.ts +7 -12
  48. package/dist/signer/signer/index.d.ts.map +1 -1
  49. package/dist/signer/signer/index.js +11 -4
  50. package/dist/utils/index.d.ts +59 -0
  51. package/dist/utils/index.d.ts.map +1 -1
  52. package/dist/utils/index.js +17 -0
  53. package/dist.commonjs/ckb/transaction.d.ts +17 -6
  54. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  55. package/dist.commonjs/ckb/transaction.js +39 -15
  56. package/dist.commonjs/client/client.d.ts +7 -6
  57. package/dist.commonjs/client/client.d.ts.map +1 -1
  58. package/dist.commonjs/client/client.js +9 -7
  59. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +1 -1
  60. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  61. package/dist.commonjs/client/clientPublicMainnet.advanced.js +1 -0
  62. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  63. package/dist.commonjs/client/clientPublicMainnet.js +5 -1
  64. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  65. package/dist.commonjs/client/clientPublicTestnet.advanced.js +4 -0
  66. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
  67. package/dist.commonjs/signer/btc/signerBtc.js +4 -2
  68. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +0 -6
  69. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  70. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +0 -8
  71. package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
  72. package/dist.commonjs/signer/btc/verify.js +5 -2
  73. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +0 -6
  74. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  75. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +0 -8
  76. package/dist.commonjs/signer/dummy/alwaysError.d.ts +0 -1
  77. package/dist.commonjs/signer/dummy/alwaysError.d.ts.map +1 -1
  78. package/dist.commonjs/signer/dummy/alwaysError.js +0 -3
  79. package/dist.commonjs/signer/dummy/openLink.d.ts +0 -1
  80. package/dist.commonjs/signer/dummy/openLink.d.ts.map +1 -1
  81. package/dist.commonjs/signer/dummy/openLink.js +0 -3
  82. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  83. package/dist.commonjs/signer/evm/signerEvm.js +3 -3
  84. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +0 -6
  85. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  86. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +0 -8
  87. package/dist.commonjs/signer/index.d.ts +1 -0
  88. package/dist.commonjs/signer/index.d.ts.map +1 -1
  89. package/dist.commonjs/signer/index.js +1 -0
  90. package/dist.commonjs/signer/nostr/index.d.ts +2 -0
  91. package/dist.commonjs/signer/nostr/index.d.ts.map +1 -0
  92. package/dist.commonjs/signer/nostr/index.js +17 -0
  93. package/dist.commonjs/signer/nostr/signerNostr.d.ts +66 -0
  94. package/dist.commonjs/signer/nostr/signerNostr.d.ts.map +1 -0
  95. package/dist.commonjs/signer/nostr/signerNostr.js +88 -0
  96. package/dist.commonjs/signer/nostr/verify.d.ts +5 -0
  97. package/dist.commonjs/signer/nostr/verify.d.ts.map +1 -0
  98. package/dist.commonjs/signer/nostr/verify.js +53 -0
  99. package/dist.commonjs/signer/signer/index.d.ts +7 -12
  100. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  101. package/dist.commonjs/signer/signer/index.js +11 -4
  102. package/dist.commonjs/utils/index.d.ts +59 -0
  103. package/dist.commonjs/utils/index.d.ts.map +1 -1
  104. package/dist.commonjs/utils/index.js +19 -1
  105. package/package.json +4 -3
  106. package/src/ckb/transaction.ts +50 -18
  107. package/src/client/client.ts +12 -10
  108. package/src/client/clientPublicMainnet.advanced.ts +2 -1
  109. package/src/client/clientPublicMainnet.ts +7 -1
  110. package/src/client/clientPublicTestnet.advanced.ts +5 -0
  111. package/src/signer/btc/signerBtc.ts +4 -7
  112. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +0 -9
  113. package/src/signer/btc/verify.ts +6 -3
  114. package/src/signer/ckb/signerCkbScriptReadonly.ts +0 -9
  115. package/src/signer/dummy/alwaysError.ts +0 -4
  116. package/src/signer/dummy/openLink.ts +0 -4
  117. package/src/signer/evm/signerEvm.ts +7 -9
  118. package/src/signer/evm/signerEvmAddressReadonly.ts +0 -9
  119. package/src/signer/index.ts +1 -0
  120. package/src/signer/nostr/index.ts +1 -0
  121. package/src/signer/nostr/signerNostr.ts +134 -0
  122. package/src/signer/nostr/verify.ts +63 -0
  123. package/src/signer/signer/index.ts +15 -11
  124. package/src/utils/index.ts +104 -0
@@ -8,7 +8,8 @@ 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
  *
@@ -1 +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;AAKhC,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;CAChB;AAED;;GAEG;AAC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Ae,GAAG,OAAO,CAAC,WAAW,CAAC;IAI5D;;;;;;OAMG;IACH,mBAAmB,CAAC,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAG9D;AAED;;GAEG;AACH,qBAAa,UAAU;IAEZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;gBADd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;CAExB;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -4,12 +4,14 @@ exports.SignerInfo = exports.Signer = exports.Signature = exports.SignerType = e
4
4
  const btc_1 = require("../btc");
5
5
  const verifyJoyId_1 = require("../ckb/verifyJoyId");
6
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,8 +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>;
7
66
  export declare function isWebview(userAgent: string): boolean;
8
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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strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isWebview = 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,6 +15,17 @@ 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;
11
29
  function isWebview(userAgent) {
12
30
  return /webview|wv|ip((?!.*Safari)|(?=.*like Safari))/i.test(userAgent);
13
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/core",
3
- "version": "0.0.5-alpha.8",
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": "f12b8758d8581bfae0c9a00abbb5f7d2c6d03147"
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
  *
@@ -1,5 +1,6 @@
1
- import { verifyMessage } from "@unisat/wallet-utils";
2
- import { BytesLike } from "../../bytes";
1
+ import { secp256k1 } from "@noble/curves/secp256k1";
2
+ import { magicHash } from "bitcoinjs-message";
3
+ import { BytesLike, bytesFrom } from "../../bytes";
3
4
  import { hexFrom } from "../../hex";
4
5
 
5
6
  export function verifyMessageBtcEcdsa(
@@ -10,5 +11,7 @@ export function verifyMessageBtcEcdsa(
10
11
  const challenge =
11
12
  typeof message === "string" ? message : hexFrom(message).slice(2);
12
13
 
13
- return verifyMessage(publicKey, challenge, signature);
14
+ const [_, ...rawSign] = bytesFrom(signature, "base64");
15
+
16
+ return secp256k1.verify(bytesFrom(rawSign), magicHash(challenge), publicKey);
14
17
  }
@@ -30,15 +30,6 @@ export class SignerCkbScriptReadonly extends Signer {
30
30
  this.script = Script.from(script);
31
31
  }
32
32
 
33
- /**
34
- * Construct a new signer with the client replaced.
35
- *
36
- * @returns A promise that resolves the new Signer.
37
- */
38
- async replaceClient(client: Client): Promise<SignerCkbScriptReadonly> {
39
- return new SignerCkbScriptReadonly(client, this.script);
40
- }
41
-
42
33
  /**
43
34
  * Connects to the client. This implementation does nothing as the class is read-only.
44
35
  *
@@ -11,10 +11,6 @@ export class SignerAlwaysError extends SignerDummy {
11
11
  super(client, type);
12
12
  }
13
13
 
14
- async replaceClient(client: Client): Promise<SignerAlwaysError> {
15
- return new SignerAlwaysError(client, this.type, this.message);
16
- }
17
-
18
14
  async connect(): Promise<void> {
19
15
  throw new Error(this.message);
20
16
  }
@@ -11,10 +11,6 @@ export class SignerOpenLink extends SignerDummy {
11
11
  super(client, type);
12
12
  }
13
13
 
14
- async replaceClient(client: Client): Promise<SignerOpenLink> {
15
- return new SignerOpenLink(client, this.type, this.link);
16
- }
17
-
18
14
  async connect(): Promise<void> {
19
15
  window.open(this.link, "_blank")?.focus();
20
16
  }
@@ -4,6 +4,7 @@ import { Script, Transaction, TransactionLike, WitnessArgs } from "../../ckb";
4
4
  import { KnownScript } from "../../client";
5
5
  import { hexFrom } from "../../hex";
6
6
  import { numToBytes } from "../../num";
7
+ import { reduceAsync } from "../../utils";
7
8
  import { Signer, SignerSignType, SignerType } from "../signer";
8
9
 
9
10
  /**
@@ -71,14 +72,11 @@ export abstract class SignerEvm extends Signer {
71
72
  * @returns A promise that resolves to the prepared Transaction object.
72
73
  */
73
74
  async prepareTransaction(txLike: TransactionLike): Promise<Transaction> {
74
- const addresses = await this.getAddressObjs();
75
-
76
- return addresses.reduce(
77
- (txPromise, { script }) =>
78
- txPromise.then((tx) =>
79
- tx.prepareSighashAllWitness(script, 85, this.client),
80
- ),
81
- Promise.resolve(Transaction.from(txLike)),
75
+ return reduceAsync(
76
+ await this.getAddressObjs(),
77
+ (tx: Transaction, { script }) =>
78
+ tx.prepareSighashAllWitness(script, 85, this.client),
79
+ Transaction.from(txLike),
82
80
  );
83
81
  }
84
82
 
@@ -139,7 +137,7 @@ export abstract class SignerEvm extends Signer {
139
137
  ),
140
138
  );
141
139
 
142
- tx.witnesses[info.position] = hexFrom(witness.toBytes());
140
+ tx.setWitnessArgsAt(info.position, witness);
143
141
 
144
142
  return tx;
145
143
  }
@@ -21,15 +21,6 @@ export class SignerEvmAddressReadonly extends SignerEvm {
21
21
  this.address = hexFrom(address);
22
22
  }
23
23
 
24
- /**
25
- * Construct a new signer with the client replaced.
26
- *
27
- * @returns A promise that resolves the new Signer.
28
- */
29
- async replaceClient(client: Client): Promise<SignerEvmAddressReadonly> {
30
- return new SignerEvmAddressReadonly(client, this.address);
31
- }
32
-
33
24
  /**
34
25
  * Connects to the client. This implementation does nothing as the class is read-only.
35
26
  *
@@ -2,4 +2,5 @@ export * from "./btc";
2
2
  export * from "./ckb";
3
3
  export * from "./dummy";
4
4
  export * from "./evm";
5
+ export * from "./nostr";
5
6
  export * from "./signer";
@@ -0,0 +1 @@
1
+ export * from "./signerNostr";