@ckb-ccc/core 0.1.0 → 0.1.2
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 +12 -0
- package/dist.commonjs/address/address.advanced.js +28 -23
- package/dist.commonjs/address/advanced.js +17 -1
- package/dist.commonjs/address/index.js +15 -11
- package/dist.commonjs/advanced.js +31 -2
- package/dist.commonjs/advancedBarrel.js +21 -5
- package/dist.commonjs/barrel.js +41 -12
- package/dist.commonjs/bytes/advanced.js +2 -1
- package/dist.commonjs/bytes/index.js +12 -7
- package/dist.commonjs/ckb/advanced.js +32 -3
- package/dist.commonjs/ckb/index.js +19 -3
- package/dist.commonjs/ckb/molecule.advanced/generated.js +131 -64
- package/dist.commonjs/ckb/molecule.advanced/index.js +19 -2
- package/dist.commonjs/ckb/script.advanced.js +6 -3
- package/dist.commonjs/ckb/script.js +53 -23
- package/dist.commonjs/ckb/transaction.advanced.js +6 -3
- package/dist.commonjs/ckb/transaction.js +163 -122
- package/dist.commonjs/ckb/transactionLumos.js +2 -1
- package/dist.commonjs/client/advanced.js +22 -6
- package/dist.commonjs/client/cache/advanced.js +17 -1
- package/dist.commonjs/client/cache/cache.js +7 -3
- package/dist.commonjs/client/cache/index.js +18 -2
- package/dist.commonjs/client/cache/memory.advanced.js +28 -21
- package/dist.commonjs/client/cache/memory.js +23 -19
- package/dist.commonjs/client/client.js +25 -21
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +25 -22
- package/dist.commonjs/client/clientPublicMainnet.js +15 -8
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +25 -22
- package/dist.commonjs/client/clientPublicTestnet.js +15 -8
- package/dist.commonjs/client/clientTypes.advanced.js +6 -3
- package/dist.commonjs/client/clientTypes.js +43 -29
- package/dist.commonjs/client/index.js +22 -6
- package/dist.commonjs/client/jsonRpc/advanced.js +18 -2
- package/dist.commonjs/client/jsonRpc/index.js +41 -37
- package/dist.commonjs/client/jsonRpc/transformers.js +61 -57
- package/dist.commonjs/client/jsonRpc/types.js +2 -1
- package/dist.commonjs/client/transports/advanced.js +25 -8
- package/dist.commonjs/client/transports/http.js +5 -1
- package/dist.commonjs/client/transports/transport.js +2 -1
- package/dist.commonjs/client/transports/webSocket.js +10 -3
- package/dist.commonjs/fixedPoint/index.js +9 -4
- package/dist.commonjs/hasher/advanced.js +4 -1
- package/dist.commonjs/hasher/hasher.js +2 -1
- package/dist.commonjs/hasher/hasherCkb.js +20 -14
- package/dist.commonjs/hasher/hasherKeecak256.js +11 -7
- package/dist.commonjs/hasher/index.js +19 -3
- package/dist.commonjs/hex/index.js +6 -3
- package/dist.commonjs/index.js +31 -2
- package/dist.commonjs/keystore/index.js +25 -21
- package/dist.commonjs/molecule/codec.js +63 -48
- package/dist.commonjs/molecule/index.js +18 -2
- package/dist.commonjs/molecule/predefined.js +103 -77
- package/dist.commonjs/num/index.js +29 -17
- package/dist.commonjs/signer/btc/index.js +19 -3
- package/dist.commonjs/signer/btc/signerBtc.js +24 -20
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +8 -4
- package/dist.commonjs/signer/btc/verify.js +26 -17
- package/dist.commonjs/signer/ckb/index.js +21 -5
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +20 -16
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +24 -20
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +12 -8
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +16 -12
- package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -5
- package/dist.commonjs/signer/doge/index.js +20 -4
- package/dist.commonjs/signer/doge/signerDoge.js +26 -19
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +6 -2
- package/dist.commonjs/signer/doge/signerDogePrivateKey.js +17 -13
- package/dist.commonjs/signer/doge/verify.js +15 -12
- package/dist.commonjs/signer/dummy/alwaysError.js +6 -2
- package/dist.commonjs/signer/dummy/dummy.js +7 -3
- package/dist.commonjs/signer/dummy/index.js +19 -3
- package/dist.commonjs/signer/dummy/openLink.js +6 -2
- package/dist.commonjs/signer/evm/index.js +19 -3
- package/dist.commonjs/signer/evm/signerEvm.js +35 -31
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +8 -4
- package/dist.commonjs/signer/evm/verify.js +7 -4
- package/dist.commonjs/signer/index.js +23 -7
- package/dist.commonjs/signer/nostr/index.js +18 -2
- package/dist.commonjs/signer/nostr/signerNostr.js +25 -21
- package/dist.commonjs/signer/nostr/verify.js +16 -12
- package/dist.commonjs/signer/signer/index.js +25 -19
- package/dist.commonjs/utils/index.js +12 -6
- package/package.json +6 -2
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerEvm = void 0;
|
|
4
|
+
const index_js_1 = require("../../address/index.js");
|
|
5
|
+
const index_js_2 = require("../../bytes/index.js");
|
|
6
|
+
const index_js_3 = require("../../ckb/index.js");
|
|
7
|
+
const index_js_4 = require("../../client/index.js");
|
|
8
|
+
const index_js_5 = require("../../hasher/index.js");
|
|
9
|
+
const index_js_6 = require("../../hex/index.js");
|
|
10
|
+
const index_js_7 = require("../../num/index.js");
|
|
11
|
+
const index_js_8 = require("../../utils/index.js");
|
|
12
|
+
const index_js_9 = require("../signer/index.js");
|
|
10
13
|
/**
|
|
11
14
|
* An abstract class extending Signer for Ethereum Virtual Machine (EVM) based signing operations.
|
|
12
15
|
* This class provides methods to get EVM account, internal address, and signing transactions.
|
|
13
16
|
* @public
|
|
14
17
|
*/
|
|
15
|
-
|
|
18
|
+
class SignerEvm extends index_js_9.Signer {
|
|
16
19
|
get type() {
|
|
17
|
-
return SignerType.EVM;
|
|
20
|
+
return index_js_9.SignerType.EVM;
|
|
18
21
|
}
|
|
19
22
|
get signType() {
|
|
20
|
-
return SignerSignType.EvmPersonal;
|
|
23
|
+
return index_js_9.SignerSignType.EvmPersonal;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* Gets the internal address, which is the EVM account in this case.
|
|
@@ -54,14 +57,14 @@ export class SignerEvm extends Signer {
|
|
|
54
57
|
return [addr];
|
|
55
58
|
}
|
|
56
59
|
async _getOmniLockEvmAddressObj(account) {
|
|
57
|
-
return Address.fromKnownScript(this.client, KnownScript.OmniLock, hexFrom([0x12, ...bytesFrom(account), 0x00]));
|
|
60
|
+
return index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.OmniLock, (0, index_js_6.hexFrom)([0x12, ...(0, index_js_2.bytesFrom)(account), 0x00]));
|
|
58
61
|
}
|
|
59
62
|
async _getOmniLockOldEvmAddressObj(account) {
|
|
60
|
-
return Address.fromKnownScript(this.client, KnownScript.OmniLock, hexFrom([0x1, ...bytesFrom(account), 0x00]));
|
|
63
|
+
return index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.OmniLock, (0, index_js_6.hexFrom)([0x1, ...(0, index_js_2.bytesFrom)(account), 0x00]));
|
|
61
64
|
}
|
|
62
65
|
async _getPWLockEvmAddressObj(account) {
|
|
63
66
|
try {
|
|
64
|
-
return Address.fromKnownScript(this.client, KnownScript.PWLock, hexFrom(bytesFrom(account)));
|
|
67
|
+
return index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.PWLock, (0, index_js_6.hexFrom)((0, index_js_2.bytesFrom)(account)));
|
|
65
68
|
}
|
|
66
69
|
catch { }
|
|
67
70
|
return;
|
|
@@ -73,18 +76,18 @@ export class SignerEvm extends Signer {
|
|
|
73
76
|
* @returns A promise that resolves to the prepared Transaction object.
|
|
74
77
|
*/
|
|
75
78
|
async prepareTransaction(txLike) {
|
|
76
|
-
const tx = Transaction.from(txLike);
|
|
77
|
-
if ((await tx.findInputIndexByLockId(await this.client.getKnownScript(KnownScript.OmniLock), this.client)) !== undefined) {
|
|
78
|
-
await tx.addCellDepsOfKnownScripts(this.client, KnownScript.OmniLock);
|
|
79
|
+
const tx = index_js_3.Transaction.from(txLike);
|
|
80
|
+
if ((await tx.findInputIndexByLockId(await this.client.getKnownScript(index_js_4.KnownScript.OmniLock), this.client)) !== undefined) {
|
|
81
|
+
await tx.addCellDepsOfKnownScripts(this.client, index_js_4.KnownScript.OmniLock);
|
|
79
82
|
}
|
|
80
|
-
if ((await tx.findInputIndexByLockId(await this.client.getKnownScript(KnownScript.PWLock), this.client)) !== undefined) {
|
|
81
|
-
await tx.addCellDepsOfKnownScripts(this.client, KnownScript.PWLock);
|
|
83
|
+
if ((await tx.findInputIndexByLockId(await this.client.getKnownScript(index_js_4.KnownScript.PWLock), this.client)) !== undefined) {
|
|
84
|
+
await tx.addCellDepsOfKnownScripts(this.client, index_js_4.KnownScript.PWLock);
|
|
82
85
|
}
|
|
83
86
|
const account = await this.getEvmAccount();
|
|
84
87
|
const omniLockAddresses = await this._getOmniLockAddresses(account);
|
|
85
88
|
const pwLockAddresses = await this._getPWLockAddresses(account);
|
|
86
|
-
const omniTx = reduceAsync(omniLockAddresses, (tx, { script }) => tx.prepareSighashAllWitness(script, 85, this.client), tx);
|
|
87
|
-
return reduceAsync(pwLockAddresses, (tx, { script }) => tx.prepareSighashAllWitness(script, 65, this.client), omniTx);
|
|
89
|
+
const omniTx = (0, index_js_8.reduceAsync)(omniLockAddresses, (tx, { script }) => tx.prepareSighashAllWitness(script, 85, this.client), tx);
|
|
90
|
+
return (0, index_js_8.reduceAsync)(pwLockAddresses, (tx, { script }) => tx.prepareSighashAllWitness(script, 65, this.client), omniTx);
|
|
88
91
|
}
|
|
89
92
|
/**
|
|
90
93
|
* Signs a transaction without modifying it.
|
|
@@ -93,15 +96,15 @@ export class SignerEvm extends Signer {
|
|
|
93
96
|
* @returns A promise that resolves to a signed Transaction object.
|
|
94
97
|
*/
|
|
95
98
|
async signOnlyTransaction(txLike) {
|
|
96
|
-
let tx = Transaction.from(txLike);
|
|
99
|
+
let tx = index_js_3.Transaction.from(txLike);
|
|
97
100
|
const account = await this.getEvmAccount();
|
|
98
101
|
const { script: evmScript } = await this._getOmniLockEvmAddressObj(account);
|
|
99
102
|
const { script: oldEvmScript } = await this._getOmniLockOldEvmAddressObj(account);
|
|
100
103
|
tx = await this._signOmniLockScriptForTransaction(tx, evmScript, (hash) => `CKB transaction: ${hash}`);
|
|
101
|
-
tx = await this._signOmniLockScriptForTransaction(tx, oldEvmScript, (hash) => bytesFrom(hash));
|
|
104
|
+
tx = await this._signOmniLockScriptForTransaction(tx, oldEvmScript, (hash) => (0, index_js_2.bytesFrom)(hash));
|
|
102
105
|
const pwAddress = await this._getPWLockEvmAddressObj(account);
|
|
103
106
|
if (pwAddress) {
|
|
104
|
-
tx = await this._signPWLockScriptForTransaction(tx, pwAddress.script, (hash) => bytesFrom(hash));
|
|
107
|
+
tx = await this._signPWLockScriptForTransaction(tx, pwAddress.script, (hash) => (0, index_js_2.bytesFrom)(hash));
|
|
105
108
|
}
|
|
106
109
|
return tx;
|
|
107
110
|
}
|
|
@@ -110,18 +113,18 @@ export class SignerEvm extends Signer {
|
|
|
110
113
|
if (!info) {
|
|
111
114
|
return tx;
|
|
112
115
|
}
|
|
113
|
-
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
114
|
-
witness.lock = hexFrom(bytesConcat(numToBytes(5 * 4 + info.signature.length, 4), numToBytes(4 * 4, 4), numToBytes(5 * 4 + info.signature.length, 4), numToBytes(5 * 4 + info.signature.length, 4), numToBytes(info.signature.length, 4), info.signature));
|
|
116
|
+
const witness = index_js_3.WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
117
|
+
witness.lock = (0, index_js_6.hexFrom)((0, index_js_2.bytesConcat)((0, index_js_7.numToBytes)(5 * 4 + info.signature.length, 4), (0, index_js_7.numToBytes)(4 * 4, 4), (0, index_js_7.numToBytes)(5 * 4 + info.signature.length, 4), (0, index_js_7.numToBytes)(5 * 4 + info.signature.length, 4), (0, index_js_7.numToBytes)(info.signature.length, 4), info.signature));
|
|
115
118
|
tx.setWitnessArgsAt(info.position, witness);
|
|
116
119
|
return tx;
|
|
117
120
|
}
|
|
118
121
|
async _signPWLockScriptForTransaction(tx, script, messageTransformer) {
|
|
119
|
-
const info = await this._signPersonalEvmForTransaction(tx, script, messageTransformer, new HasherKeecak256());
|
|
122
|
+
const info = await this._signPersonalEvmForTransaction(tx, script, messageTransformer, new index_js_5.HasherKeecak256());
|
|
120
123
|
if (!info) {
|
|
121
124
|
return tx;
|
|
122
125
|
}
|
|
123
|
-
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
124
|
-
witness.lock = hexFrom(info.signature);
|
|
126
|
+
const witness = index_js_3.WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
127
|
+
witness.lock = (0, index_js_6.hexFrom)(info.signature);
|
|
125
128
|
tx.setWitnessArgsAt(info.position, witness);
|
|
126
129
|
return tx;
|
|
127
130
|
}
|
|
@@ -130,10 +133,11 @@ export class SignerEvm extends Signer {
|
|
|
130
133
|
if (!info) {
|
|
131
134
|
return;
|
|
132
135
|
}
|
|
133
|
-
const signature = bytesFrom(await this.signMessageRaw(messageTransformer(info.message)));
|
|
136
|
+
const signature = (0, index_js_2.bytesFrom)(await this.signMessageRaw(messageTransformer(info.message)));
|
|
134
137
|
if (signature[signature.length - 1] >= 27) {
|
|
135
138
|
signature[signature.length - 1] -= 27;
|
|
136
139
|
}
|
|
137
140
|
return { signature, position: info.position };
|
|
138
141
|
}
|
|
139
142
|
}
|
|
143
|
+
exports.SignerEvm = SignerEvm;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerEvmAddressReadonly = void 0;
|
|
4
|
+
const index_js_1 = require("../../hex/index.js");
|
|
5
|
+
const signerEvm_js_1 = require("./signerEvm.js");
|
|
3
6
|
/**
|
|
4
7
|
* A class extending SignerEvm that provides read-only access to an EVM address.
|
|
5
8
|
* This class does not support signing operations.
|
|
6
9
|
* @public
|
|
7
10
|
*/
|
|
8
|
-
|
|
11
|
+
class SignerEvmAddressReadonly extends signerEvm_js_1.SignerEvm {
|
|
9
12
|
/**
|
|
10
13
|
* Creates an instance of SignerEvmAddressReadonly.
|
|
11
14
|
*
|
|
@@ -14,7 +17,7 @@ export class SignerEvmAddressReadonly extends SignerEvm {
|
|
|
14
17
|
*/
|
|
15
18
|
constructor(client, address) {
|
|
16
19
|
super(client);
|
|
17
|
-
this.address = hexFrom(address);
|
|
20
|
+
this.address = (0, index_js_1.hexFrom)(address);
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
23
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
@@ -49,3 +52,4 @@ export class SignerEvmAddressReadonly extends SignerEvm {
|
|
|
49
52
|
return this.address;
|
|
50
53
|
}
|
|
51
54
|
}
|
|
55
|
+
exports.SignerEvmAddressReadonly = SignerEvmAddressReadonly;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyMessageEvmPersonal = verifyMessageEvmPersonal;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const index_js_1 = require("../../bytes/index.js");
|
|
3
6
|
/**
|
|
4
7
|
* @public
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
function verifyMessageEvmPersonal(message, signature, address) {
|
|
7
10
|
return (address.toLowerCase() ===
|
|
8
|
-
verifyMessage(typeof message === "string" ? message : bytesFrom(message), signature).toLowerCase());
|
|
11
|
+
(0, ethers_1.verifyMessage)(typeof message === "string" ? message : (0, index_js_1.bytesFrom)(message), signature).toLowerCase());
|
|
9
12
|
}
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
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("./btc/index.js"), exports);
|
|
18
|
+
__exportStar(require("./ckb/index.js"), exports);
|
|
19
|
+
__exportStar(require("./doge/index.js"), exports);
|
|
20
|
+
__exportStar(require("./dummy/index.js"), exports);
|
|
21
|
+
__exportStar(require("./evm/index.js"), exports);
|
|
22
|
+
__exportStar(require("./nostr/index.js"), exports);
|
|
23
|
+
__exportStar(require("./signer/index.js"), exports);
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
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("./signerNostr.js"), exports);
|
|
18
|
+
__exportStar(require("./verify.js"), exports);
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerNostr = void 0;
|
|
4
|
+
const bech32_1 = require("bech32");
|
|
5
|
+
const index_js_1 = require("../../address/index.js");
|
|
6
|
+
const index_js_2 = require("../../bytes/index.js");
|
|
7
|
+
const index_js_3 = require("../../ckb/index.js");
|
|
8
|
+
const index_js_4 = require("../../client/index.js");
|
|
9
|
+
const index_js_5 = require("../../hasher/index.js");
|
|
10
|
+
const index_js_6 = require("../../hex/index.js");
|
|
11
|
+
const index_js_7 = require("../signer/index.js");
|
|
12
|
+
const verify_js_1 = require("./verify.js");
|
|
10
13
|
/**
|
|
11
14
|
* @public
|
|
12
15
|
*/
|
|
13
|
-
|
|
16
|
+
class SignerNostr extends index_js_7.Signer {
|
|
14
17
|
get type() {
|
|
15
|
-
return SignerType.Nostr;
|
|
18
|
+
return index_js_7.SignerType.Nostr;
|
|
16
19
|
}
|
|
17
20
|
get signType() {
|
|
18
|
-
return SignerSignType.NostrEvent;
|
|
21
|
+
return index_js_7.SignerSignType.NostrEvent;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Sign a message.
|
|
@@ -23,7 +26,7 @@ export class SignerNostr extends Signer {
|
|
|
23
26
|
* @returns A promise that resolves to the signature.
|
|
24
27
|
*/
|
|
25
28
|
async signMessageRaw(message) {
|
|
26
|
-
return hexFrom((await this.signNostrEvent(buildNostrEventFromMessage(message))).sig);
|
|
29
|
+
return (0, index_js_6.hexFrom)((await this.signNostrEvent((0, verify_js_1.buildNostrEventFromMessage)(message))).sig);
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
29
32
|
* Gets the internal address, which is the EVM account in this case.
|
|
@@ -31,7 +34,7 @@ export class SignerNostr extends Signer {
|
|
|
31
34
|
* @returns A promise that resolves to a string representing the internal address.
|
|
32
35
|
*/
|
|
33
36
|
async getInternalAddress() {
|
|
34
|
-
return bech32.encode("npub", bech32.toWords(bytesFrom(await this.getNostrPublicKey())));
|
|
37
|
+
return bech32_1.bech32.encode("npub", bech32_1.bech32.toWords((0, index_js_2.bytesFrom)(await this.getNostrPublicKey())));
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
40
|
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
@@ -41,7 +44,7 @@ export class SignerNostr extends Signer {
|
|
|
41
44
|
async getAddressObjs() {
|
|
42
45
|
const publicKey = await this.getNostrPublicKey();
|
|
43
46
|
return [
|
|
44
|
-
await Address.fromKnownScript(this.client, KnownScript.NostrLock, hexFrom(bytesConcat([0x00], hashCkb(publicKey).slice(0, 42)))),
|
|
47
|
+
await index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.NostrLock, (0, index_js_6.hexFrom)((0, index_js_2.bytesConcat)([0x00], (0, index_js_5.hashCkb)(publicKey).slice(0, 42)))),
|
|
45
48
|
];
|
|
46
49
|
}
|
|
47
50
|
/**
|
|
@@ -51,9 +54,9 @@ export class SignerNostr extends Signer {
|
|
|
51
54
|
* @returns A promise that resolves to the prepared Transaction object.
|
|
52
55
|
*/
|
|
53
56
|
async prepareTransaction(txLike) {
|
|
54
|
-
const tx = Transaction.from(txLike);
|
|
57
|
+
const tx = index_js_3.Transaction.from(txLike);
|
|
55
58
|
const { script } = await this.getRecommendedAddressObj();
|
|
56
|
-
await tx.addCellDepsOfKnownScripts(this.client, KnownScript.NostrLock);
|
|
59
|
+
await tx.addCellDepsOfKnownScripts(this.client, index_js_4.KnownScript.NostrLock);
|
|
57
60
|
await tx.prepareSighashAllWitness(script, 572, this.client);
|
|
58
61
|
return tx;
|
|
59
62
|
}
|
|
@@ -64,25 +67,26 @@ export class SignerNostr extends Signer {
|
|
|
64
67
|
* @returns A promise that resolves to a signed Transaction object.
|
|
65
68
|
*/
|
|
66
69
|
async signOnlyTransaction(txLike) {
|
|
67
|
-
const tx = Transaction.from(txLike);
|
|
70
|
+
const tx = index_js_3.Transaction.from(txLike);
|
|
68
71
|
const { script } = await this.getRecommendedAddressObj();
|
|
69
72
|
const info = await tx.getSignHashInfo(script, this.client);
|
|
70
73
|
if (!info) {
|
|
71
74
|
return tx;
|
|
72
75
|
}
|
|
73
|
-
const signedEvent = bytesFrom(JSON.stringify(await this.signNostrEvent({
|
|
76
|
+
const signedEvent = (0, index_js_2.bytesFrom)(JSON.stringify(await this.signNostrEvent({
|
|
74
77
|
pubkey: (await this.getNostrPublicKey()).slice(2),
|
|
75
78
|
tags: [[SignerNostr.CKB_SIG_HASH_ALL_TAG, info.message.slice(2)]],
|
|
76
79
|
created_at: Math.floor(Date.now() / 1000),
|
|
77
80
|
kind: SignerNostr.CKB_UNLOCK_EVENT_KIND,
|
|
78
81
|
content: SignerNostr.CKB_UNLOCK_EVENT_CONTENT,
|
|
79
82
|
})), "utf8");
|
|
80
|
-
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
81
|
-
witness.lock = hexFrom(signedEvent);
|
|
83
|
+
const witness = index_js_3.WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
84
|
+
witness.lock = (0, index_js_6.hexFrom)(signedEvent);
|
|
82
85
|
tx.setWitnessArgsAt(info.position, witness);
|
|
83
86
|
return tx;
|
|
84
87
|
}
|
|
85
88
|
}
|
|
89
|
+
exports.SignerNostr = SignerNostr;
|
|
86
90
|
SignerNostr.CKB_SIG_HASH_ALL_TAG = "ckb_sighash_all";
|
|
87
91
|
SignerNostr.CKB_UNLOCK_EVENT_KIND = 23334;
|
|
88
92
|
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";
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildNostrEventFromMessage = buildNostrEventFromMessage;
|
|
4
|
+
exports.verifyMessageNostrEvent = verifyMessageNostrEvent;
|
|
5
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
6
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
7
|
+
const bech32_1 = require("bech32");
|
|
8
|
+
const index_js_1 = require("../../bytes/index.js");
|
|
9
|
+
const index_js_2 = require("../../hex/index.js");
|
|
6
10
|
/**
|
|
7
11
|
* @public
|
|
8
12
|
*/
|
|
9
|
-
|
|
13
|
+
function buildNostrEventFromMessage(message) {
|
|
10
14
|
if (typeof message === "string") {
|
|
11
15
|
try {
|
|
12
16
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -26,13 +30,13 @@ export function buildNostrEventFromMessage(message) {
|
|
|
26
30
|
return {
|
|
27
31
|
kind: 23335,
|
|
28
32
|
created_at: 0,
|
|
29
|
-
content: typeof message === "string" ? message : hexFrom(message),
|
|
33
|
+
content: typeof message === "string" ? message : (0, index_js_2.hexFrom)(message),
|
|
30
34
|
tags: [],
|
|
31
35
|
};
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
const { words } = bech32.decode(address);
|
|
35
|
-
const publicKey = hexFrom(bech32.fromWords(words)).slice(2);
|
|
37
|
+
function verifyMessageNostrEvent(message, signature, address) {
|
|
38
|
+
const { words } = bech32_1.bech32.decode(address);
|
|
39
|
+
const publicKey = (0, index_js_2.hexFrom)(bech32_1.bech32.fromWords(words)).slice(2);
|
|
36
40
|
const event = buildNostrEventFromMessage(message);
|
|
37
41
|
const serialized = JSON.stringify([
|
|
38
42
|
0,
|
|
@@ -42,9 +46,9 @@ export function verifyMessageNostrEvent(message, signature, address) {
|
|
|
42
46
|
event.tags,
|
|
43
47
|
event.content,
|
|
44
48
|
]);
|
|
45
|
-
const eventHash = hexFrom(sha256(bytesFrom(serialized, "utf8")));
|
|
49
|
+
const eventHash = (0, index_js_2.hexFrom)((0, sha256_1.sha256)((0, index_js_1.bytesFrom)(serialized, "utf8")));
|
|
46
50
|
try {
|
|
47
|
-
return schnorr.verify(signature.slice(2), eventHash.slice(2), publicKey);
|
|
51
|
+
return secp256k1_1.schnorr.verify(signature.slice(2), eventHash.slice(2), publicKey);
|
|
48
52
|
}
|
|
49
53
|
catch (_) {
|
|
50
54
|
return false;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerInfo = exports.Signer = exports.Signature = exports.SignerType = exports.SignerSignType = void 0;
|
|
4
|
+
const index_js_1 = require("../btc/index.js");
|
|
5
|
+
const verifyCkbSecp256k1_js_1 = require("../ckb/verifyCkbSecp256k1.js");
|
|
6
|
+
const verifyJoyId_js_1 = require("../ckb/verifyJoyId.js");
|
|
7
|
+
const verify_js_1 = require("../doge/verify.js");
|
|
8
|
+
const verify_js_2 = require("../evm/verify.js");
|
|
9
|
+
const verify_js_3 = require("../nostr/verify.js");
|
|
7
10
|
/**
|
|
8
11
|
* @public
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
var SignerSignType;
|
|
11
14
|
(function (SignerSignType) {
|
|
12
15
|
SignerSignType["Unknown"] = "Unknown";
|
|
13
16
|
SignerSignType["BtcEcdsa"] = "BtcEcdsa";
|
|
@@ -16,35 +19,36 @@ export var SignerSignType;
|
|
|
16
19
|
SignerSignType["NostrEvent"] = "NostrEvent";
|
|
17
20
|
SignerSignType["CkbSecp256k1"] = "CkbSecp256k1";
|
|
18
21
|
SignerSignType["DogeEcdsa"] = "DogeEcdsa";
|
|
19
|
-
})(SignerSignType || (SignerSignType = {}));
|
|
22
|
+
})(SignerSignType || (exports.SignerSignType = SignerSignType = {}));
|
|
20
23
|
/**
|
|
21
24
|
* An enumeration of signer display types in wallet.
|
|
22
25
|
* @public
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
var SignerType;
|
|
25
28
|
(function (SignerType) {
|
|
26
29
|
SignerType["EVM"] = "EVM";
|
|
27
30
|
SignerType["BTC"] = "BTC";
|
|
28
31
|
SignerType["CKB"] = "CKB";
|
|
29
32
|
SignerType["Nostr"] = "Nostr";
|
|
30
33
|
SignerType["Doge"] = "Doge";
|
|
31
|
-
})(SignerType || (SignerType = {}));
|
|
34
|
+
})(SignerType || (exports.SignerType = SignerType = {}));
|
|
32
35
|
/**
|
|
33
36
|
* @public
|
|
34
37
|
*/
|
|
35
|
-
|
|
38
|
+
class Signature {
|
|
36
39
|
constructor(signature, identity, signType) {
|
|
37
40
|
this.signature = signature;
|
|
38
41
|
this.identity = identity;
|
|
39
42
|
this.signType = signType;
|
|
40
43
|
}
|
|
41
44
|
}
|
|
45
|
+
exports.Signature = Signature;
|
|
42
46
|
/**
|
|
43
47
|
* An abstract class representing a generic signer.
|
|
44
48
|
* This class provides methods to connect, get addresses, and sign transactions.
|
|
45
49
|
* @public
|
|
46
50
|
*/
|
|
47
|
-
|
|
51
|
+
class Signer {
|
|
48
52
|
constructor(client_) {
|
|
49
53
|
this.client_ = client_;
|
|
50
54
|
}
|
|
@@ -67,17 +71,17 @@ export class Signer {
|
|
|
67
71
|
static async verifyMessage(message, signature) {
|
|
68
72
|
switch (signature.signType) {
|
|
69
73
|
case SignerSignType.EvmPersonal:
|
|
70
|
-
return verifyMessageEvmPersonal(message, signature.signature, signature.identity);
|
|
74
|
+
return (0, verify_js_2.verifyMessageEvmPersonal)(message, signature.signature, signature.identity);
|
|
71
75
|
case SignerSignType.BtcEcdsa:
|
|
72
|
-
return verifyMessageBtcEcdsa(message, signature.signature, signature.identity);
|
|
76
|
+
return (0, index_js_1.verifyMessageBtcEcdsa)(message, signature.signature, signature.identity);
|
|
73
77
|
case SignerSignType.JoyId:
|
|
74
|
-
return verifyMessageJoyId(message, signature.signature, signature.identity);
|
|
78
|
+
return (0, verifyJoyId_js_1.verifyMessageJoyId)(message, signature.signature, signature.identity);
|
|
75
79
|
case SignerSignType.NostrEvent:
|
|
76
|
-
return verifyMessageNostrEvent(message, signature.signature, signature.identity);
|
|
80
|
+
return (0, verify_js_3.verifyMessageNostrEvent)(message, signature.signature, signature.identity);
|
|
77
81
|
case SignerSignType.CkbSecp256k1:
|
|
78
|
-
return verifyMessageCkbSecp256k1(message, signature.signature, signature.identity);
|
|
82
|
+
return (0, verifyCkbSecp256k1_js_1.verifyMessageCkbSecp256k1)(message, signature.signature, signature.identity);
|
|
79
83
|
case SignerSignType.DogeEcdsa:
|
|
80
|
-
return verifyMessageDogeEcdsa(message, signature.signature, signature.identity);
|
|
84
|
+
return (0, verify_js_1.verifyMessageDogeEcdsa)(message, signature.signature, signature.identity);
|
|
81
85
|
case SignerSignType.Unknown:
|
|
82
86
|
throw new Error("Unknown signer sign type");
|
|
83
87
|
}
|
|
@@ -262,13 +266,15 @@ export class Signer {
|
|
|
262
266
|
throw Error("Signer.signOnlyTransaction not implemented");
|
|
263
267
|
}
|
|
264
268
|
}
|
|
269
|
+
exports.Signer = Signer;
|
|
265
270
|
/**
|
|
266
271
|
* A class representing information about a signer, including its type and the signer instance.
|
|
267
272
|
* @public
|
|
268
273
|
*/
|
|
269
|
-
|
|
274
|
+
class SignerInfo {
|
|
270
275
|
constructor(name, signer) {
|
|
271
276
|
this.name = name;
|
|
272
277
|
this.signer = signer;
|
|
273
278
|
}
|
|
274
279
|
}
|
|
280
|
+
exports.SignerInfo = SignerInfo;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.apply = apply;
|
|
4
|
+
exports.reduceAsync = reduceAsync;
|
|
5
|
+
exports.sleep = sleep;
|
|
6
|
+
exports.isWebview = isWebview;
|
|
7
|
+
const index_js_1 = require("../num/index.js");
|
|
2
8
|
/**
|
|
3
9
|
* A type safe way to apply a transformer on a value if it's not empty.
|
|
4
10
|
* @public
|
|
@@ -7,7 +13,7 @@ import { numFrom } from "../num/index.js";
|
|
|
7
13
|
* @param value - The value to be transformed.
|
|
8
14
|
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
9
15
|
*/
|
|
10
|
-
|
|
16
|
+
function apply(transformer, value) {
|
|
11
17
|
if (value == null) {
|
|
12
18
|
return undefined;
|
|
13
19
|
}
|
|
@@ -22,7 +28,7 @@ export function apply(transformer, value) {
|
|
|
22
28
|
* @param init - The initial value.
|
|
23
29
|
* @returns The accumulated result.
|
|
24
30
|
*/
|
|
25
|
-
|
|
31
|
+
async function reduceAsync(values, accumulator, init) {
|
|
26
32
|
if (init === undefined) {
|
|
27
33
|
if (values.length === 0) {
|
|
28
34
|
throw new TypeError("Reduce of empty array with no initial value");
|
|
@@ -32,12 +38,12 @@ export async function reduceAsync(values, accumulator, init) {
|
|
|
32
38
|
}
|
|
33
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));
|
|
34
40
|
}
|
|
35
|
-
|
|
36
|
-
return new Promise((resolve) => setTimeout(resolve, Number(numFrom(ms))));
|
|
41
|
+
function sleep(ms) {
|
|
42
|
+
return new Promise((resolve) => setTimeout(resolve, Number((0, index_js_1.numFrom)(ms))));
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
39
45
|
* @public
|
|
40
46
|
*/
|
|
41
|
-
|
|
47
|
+
function isWebview(userAgent) {
|
|
42
48
|
return /webview|wv|ip((?!.*Safari)|(?=.*like Safari))/i.test(userAgent);
|
|
43
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Core of CCC - CKBer's Codebase",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,24 +10,28 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git://github.com/ckb-devrel/ccc.git"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
13
|
+
"sideEffects": false,
|
|
14
14
|
"main": "./dist.commonjs/index.js",
|
|
15
15
|
"module": "./dist/index.js",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist.commonjs/index.js",
|
|
19
20
|
"default": "./dist.commonjs/index.js"
|
|
20
21
|
},
|
|
21
22
|
"./barrel": {
|
|
22
23
|
"import": "./dist/barrel.js",
|
|
24
|
+
"require": "./dist.commonjs/barrel.js",
|
|
23
25
|
"default": "./dist.commonjs/barrel.js"
|
|
24
26
|
},
|
|
25
27
|
"./advancedBarrel": {
|
|
26
28
|
"import": "./dist/advancedBarrel.js",
|
|
29
|
+
"require": "./dist.commonjs/advancedBarrel.js",
|
|
27
30
|
"default": "./dist.commonjs/advancedBarrel.js"
|
|
28
31
|
},
|
|
29
32
|
"./advanced": {
|
|
30
33
|
"import": "./dist/advanced.js",
|
|
34
|
+
"require": "./dist.commonjs/advanced.js",
|
|
31
35
|
"default": "./dist.commonjs/advanced.js"
|
|
32
36
|
}
|
|
33
37
|
},
|