@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,24 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerCkbPublicKey = 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("../signer/index.js");
|
|
8
11
|
/**
|
|
9
12
|
* @public
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
class SignerCkbPublicKey extends index_js_7.Signer {
|
|
12
15
|
get type() {
|
|
13
|
-
return SignerType.CKB;
|
|
16
|
+
return index_js_7.SignerType.CKB;
|
|
14
17
|
}
|
|
15
18
|
get signType() {
|
|
16
|
-
return SignerSignType.CkbSecp256k1;
|
|
19
|
+
return index_js_7.SignerSignType.CkbSecp256k1;
|
|
17
20
|
}
|
|
18
21
|
constructor(client, publicKey) {
|
|
19
22
|
super(client);
|
|
20
|
-
this.publicKey = hexFrom(publicKey);
|
|
21
|
-
if (bytesFrom(this.publicKey).length !== 33) {
|
|
23
|
+
this.publicKey = (0, index_js_6.hexFrom)(publicKey);
|
|
24
|
+
if ((0, index_js_2.bytesFrom)(this.publicKey).length !== 33) {
|
|
22
25
|
throw new Error("Public key must be 33 bytes!");
|
|
23
26
|
}
|
|
24
27
|
}
|
|
@@ -33,7 +36,7 @@ export class SignerCkbPublicKey extends Signer {
|
|
|
33
36
|
return this.publicKey;
|
|
34
37
|
}
|
|
35
38
|
async getAddressObjSecp256k1() {
|
|
36
|
-
return Address.fromKnownScript(this.client, KnownScript.Secp256k1Blake160, bytesFrom(hashCkb(this.publicKey)).slice(0, 20));
|
|
39
|
+
return index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.Secp256k1Blake160, (0, index_js_2.bytesFrom)((0, index_js_5.hashCkb)(this.publicKey)).slice(0, 20));
|
|
37
40
|
}
|
|
38
41
|
async getRecommendedAddressObj(_preference) {
|
|
39
42
|
return this.getAddressObjSecp256k1();
|
|
@@ -43,7 +46,7 @@ export class SignerCkbPublicKey extends Signer {
|
|
|
43
46
|
const addresses = [];
|
|
44
47
|
let count = 0;
|
|
45
48
|
for await (const cell of this.client.findCells({
|
|
46
|
-
script: await Script.fromKnownScript(this.client, KnownScript.AnyoneCanPay, secp256k1.script.args),
|
|
49
|
+
script: await index_js_3.Script.fromKnownScript(this.client, index_js_4.KnownScript.AnyoneCanPay, secp256k1.script.args),
|
|
47
50
|
scriptType: "lock",
|
|
48
51
|
scriptSearchMode: "prefix",
|
|
49
52
|
withData: false,
|
|
@@ -55,7 +58,7 @@ export class SignerCkbPublicKey extends Signer {
|
|
|
55
58
|
if (addresses.some(({ script }) => script.eq(cell.cellOutput.lock))) {
|
|
56
59
|
continue;
|
|
57
60
|
}
|
|
58
|
-
addresses.push(Address.from({
|
|
61
|
+
addresses.push(index_js_1.Address.from({
|
|
59
62
|
prefix: this.client.addressPrefix,
|
|
60
63
|
script: cell.cellOutput.lock,
|
|
61
64
|
}));
|
|
@@ -63,9 +66,9 @@ export class SignerCkbPublicKey extends Signer {
|
|
|
63
66
|
return [secp256k1, ...addresses];
|
|
64
67
|
}
|
|
65
68
|
async getRelatedScripts(txLike) {
|
|
66
|
-
const tx = Transaction.from(txLike);
|
|
69
|
+
const tx = index_js_3.Transaction.from(txLike);
|
|
67
70
|
const secp256k1 = await this.getAddressObjSecp256k1();
|
|
68
|
-
const acp = await Script.fromKnownScript(this.client, KnownScript.AnyoneCanPay, secp256k1.script.args);
|
|
71
|
+
const acp = await index_js_3.Script.fromKnownScript(this.client, index_js_4.KnownScript.AnyoneCanPay, secp256k1.script.args);
|
|
69
72
|
const scripts = [];
|
|
70
73
|
for (const input of tx.inputs) {
|
|
71
74
|
await input.completeExtraInfos(this.client);
|
|
@@ -79,7 +82,7 @@ export class SignerCkbPublicKey extends Signer {
|
|
|
79
82
|
if (lock.eq(secp256k1.script)) {
|
|
80
83
|
scripts.push({
|
|
81
84
|
script: lock,
|
|
82
|
-
cellDeps: (await this.client.getKnownScript(KnownScript.Secp256k1Blake160)).cellDeps,
|
|
85
|
+
cellDeps: (await this.client.getKnownScript(index_js_4.KnownScript.Secp256k1Blake160)).cellDeps,
|
|
83
86
|
});
|
|
84
87
|
}
|
|
85
88
|
else if (lock.codeHash === acp.codeHash &&
|
|
@@ -87,7 +90,7 @@ export class SignerCkbPublicKey extends Signer {
|
|
|
87
90
|
lock.args.startsWith(acp.args)) {
|
|
88
91
|
scripts.push({
|
|
89
92
|
script: lock,
|
|
90
|
-
cellDeps: (await this.client.getKnownScript(KnownScript.AnyoneCanPay))
|
|
93
|
+
cellDeps: (await this.client.getKnownScript(index_js_4.KnownScript.AnyoneCanPay))
|
|
91
94
|
.cellDeps,
|
|
92
95
|
});
|
|
93
96
|
}
|
|
@@ -95,7 +98,7 @@ export class SignerCkbPublicKey extends Signer {
|
|
|
95
98
|
return scripts;
|
|
96
99
|
}
|
|
97
100
|
async prepareTransaction(txLike) {
|
|
98
|
-
const tx = Transaction.from(txLike);
|
|
101
|
+
const tx = index_js_3.Transaction.from(txLike);
|
|
99
102
|
await Promise.all((await this.getRelatedScripts(tx)).map(async ({ script, cellDeps }) => {
|
|
100
103
|
await tx.prepareSighashAllWitness(script, 65, this.client);
|
|
101
104
|
await tx.addCellDepInfos(this.client, cellDeps);
|
|
@@ -103,3 +106,4 @@ export class SignerCkbPublicKey extends Signer {
|
|
|
103
106
|
return tx;
|
|
104
107
|
}
|
|
105
108
|
}
|
|
109
|
+
exports.SignerCkbPublicKey = SignerCkbPublicKey;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerCkbScriptReadonly = void 0;
|
|
4
|
+
const index_js_1 = require("../../address/index.js");
|
|
5
|
+
const index_js_2 = require("../../ckb/index.js");
|
|
6
|
+
const index_js_3 = require("../signer/index.js");
|
|
4
7
|
/**
|
|
5
8
|
* A class extending Signer that provides read-only access to a CKB script.
|
|
6
9
|
* This class does not support signing operations.
|
|
7
10
|
* @public
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
class SignerCkbScriptReadonly extends index_js_3.Signer {
|
|
10
13
|
get type() {
|
|
11
|
-
return SignerType.CKB;
|
|
14
|
+
return index_js_3.SignerType.CKB;
|
|
12
15
|
}
|
|
13
16
|
get signType() {
|
|
14
|
-
return SignerSignType.Unknown;
|
|
17
|
+
return index_js_3.SignerSignType.Unknown;
|
|
15
18
|
}
|
|
16
19
|
/**
|
|
17
20
|
* Creates an instance of SignerCkbScriptReadonly.
|
|
@@ -21,7 +24,7 @@ export class SignerCkbScriptReadonly extends Signer {
|
|
|
21
24
|
*/
|
|
22
25
|
constructor(client, script) {
|
|
23
26
|
super(client);
|
|
24
|
-
this.script = Script.from(script);
|
|
27
|
+
this.script = index_js_2.Script.from(script);
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
27
30
|
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
@@ -61,6 +64,7 @@ export class SignerCkbScriptReadonly extends Signer {
|
|
|
61
64
|
* ```
|
|
62
65
|
*/
|
|
63
66
|
async getAddressObjs() {
|
|
64
|
-
return [Address.fromScript(this.script, this.client)];
|
|
67
|
+
return [index_js_1.Address.fromScript(this.script, this.client)];
|
|
65
68
|
}
|
|
66
69
|
}
|
|
70
|
+
exports.SignerCkbScriptReadonly = SignerCkbScriptReadonly;
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.messageHashCkbSecp256k1 = messageHashCkbSecp256k1;
|
|
4
|
+
exports.verifyMessageCkbSecp256k1 = verifyMessageCkbSecp256k1;
|
|
5
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
6
|
+
const index_js_1 = require("../../bytes/index.js");
|
|
7
|
+
const index_js_2 = require("../../hasher/index.js");
|
|
8
|
+
const index_js_3 = require("../../hex/index.js");
|
|
9
|
+
const index_js_4 = require("../../num/index.js");
|
|
6
10
|
/**
|
|
7
11
|
* @public
|
|
8
12
|
*/
|
|
9
|
-
|
|
10
|
-
const msg = typeof message === "string" ? message : hexFrom(message);
|
|
11
|
-
const buffer = bytesFrom(`Nervos Message:${msg}`, "utf8");
|
|
12
|
-
return hashCkb(buffer);
|
|
13
|
+
function messageHashCkbSecp256k1(message) {
|
|
14
|
+
const msg = typeof message === "string" ? message : (0, index_js_3.hexFrom)(message);
|
|
15
|
+
const buffer = (0, index_js_1.bytesFrom)(`Nervos Message:${msg}`, "utf8");
|
|
16
|
+
return (0, index_js_2.hashCkb)(buffer);
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
19
|
* @public
|
|
16
20
|
*/
|
|
17
|
-
|
|
18
|
-
const signatureBytes = bytesFrom(signature);
|
|
19
|
-
return secp256k1.verify(new secp256k1.Signature(numFrom(signatureBytes.slice(0, 32)), numFrom(signatureBytes.slice(32, 64))).addRecoveryBit(Number(numFrom(signatureBytes.slice(64, 65)))), bytesFrom(messageHashCkbSecp256k1(message)), bytesFrom(publicKey));
|
|
21
|
+
function verifyMessageCkbSecp256k1(message, signature, publicKey) {
|
|
22
|
+
const signatureBytes = (0, index_js_1.bytesFrom)(signature);
|
|
23
|
+
return secp256k1_1.secp256k1.verify(new secp256k1_1.secp256k1.Signature((0, index_js_4.numFrom)(signatureBytes.slice(0, 32)), (0, index_js_4.numFrom)(signatureBytes.slice(32, 64))).addRecoveryBit(Number((0, index_js_4.numFrom)(signatureBytes.slice(64, 65)))), (0, index_js_1.bytesFrom)(messageHashCkbSecp256k1(message)), (0, index_js_1.bytesFrom)(publicKey));
|
|
20
24
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyMessageJoyId = verifyMessageJoyId;
|
|
4
|
+
const ckb_1 = require("@joyid/ckb");
|
|
5
|
+
const index_js_1 = require("../../hex/index.js");
|
|
3
6
|
/**
|
|
4
7
|
* @public
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
const challenge = typeof message === "string" ? message : hexFrom(message).slice(2);
|
|
9
|
+
function verifyMessageJoyId(message, signature, identity) {
|
|
10
|
+
const challenge = typeof message === "string" ? message : (0, index_js_1.hexFrom)(message).slice(2);
|
|
8
11
|
const { publicKey, keyType } = JSON.parse(identity);
|
|
9
12
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
10
|
-
return verifySignature({
|
|
13
|
+
return (0, ckb_1.verifySignature)({
|
|
11
14
|
challenge,
|
|
12
15
|
pubkey: publicKey,
|
|
13
16
|
keyType,
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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("./signerDoge.js"), exports);
|
|
18
|
+
__exportStar(require("./signerDogeAddressReadonly.js"), exports);
|
|
19
|
+
__exportStar(require("./signerDogePrivateKey.js"), exports);
|
|
20
|
+
__exportStar(require("./verify.js"), exports);
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SignerDoge = void 0;
|
|
7
|
+
const bs58check_1 = __importDefault(require("bs58check"));
|
|
8
|
+
const index_js_1 = require("../../address/index.js");
|
|
9
|
+
const index_js_2 = require("../../bytes/index.js");
|
|
10
|
+
const index_js_3 = require("../../ckb/index.js");
|
|
11
|
+
const index_js_4 = require("../../client/index.js");
|
|
12
|
+
const index_js_5 = require("../../hex/index.js");
|
|
13
|
+
const index_js_6 = require("../../num/index.js");
|
|
14
|
+
const index_js_7 = require("../signer/index.js");
|
|
9
15
|
/**
|
|
10
16
|
* An abstract class extending the Signer class for Dogecoin-like signing operations.
|
|
11
17
|
* This class provides methods to get Doge account, public key, and internal address,
|
|
12
18
|
* as well as signing transactions.
|
|
13
19
|
* @public
|
|
14
20
|
*/
|
|
15
|
-
|
|
21
|
+
class SignerDoge extends index_js_7.Signer {
|
|
16
22
|
get type() {
|
|
17
|
-
return SignerType.Doge;
|
|
23
|
+
return index_js_7.SignerType.Doge;
|
|
18
24
|
}
|
|
19
25
|
get signType() {
|
|
20
|
-
return SignerSignType.DogeEcdsa;
|
|
26
|
+
return index_js_7.SignerSignType.DogeEcdsa;
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
29
|
* Gets the internal address, which is the Doge account in this case.
|
|
@@ -41,9 +47,9 @@ export class SignerDoge extends Signer {
|
|
|
41
47
|
* @returns A promise that resolves to an array of Address objects.
|
|
42
48
|
*/
|
|
43
49
|
async getAddressObjs() {
|
|
44
|
-
const hash =
|
|
50
|
+
const hash = bs58check_1.default.decode(await this.getDogeAddress()).slice(1);
|
|
45
51
|
return [
|
|
46
|
-
await Address.fromKnownScript(this.client, KnownScript.OmniLock, hexFrom([0x05, ...hash, 0x00])),
|
|
52
|
+
await index_js_1.Address.fromKnownScript(this.client, index_js_4.KnownScript.OmniLock, (0, index_js_5.hexFrom)([0x05, ...hash, 0x00])),
|
|
47
53
|
];
|
|
48
54
|
}
|
|
49
55
|
/**
|
|
@@ -53,9 +59,9 @@ export class SignerDoge extends Signer {
|
|
|
53
59
|
* @returns A promise that resolves to the prepared Transaction object.
|
|
54
60
|
*/
|
|
55
61
|
async prepareTransaction(txLike) {
|
|
56
|
-
const tx = Transaction.from(txLike);
|
|
62
|
+
const tx = index_js_3.Transaction.from(txLike);
|
|
57
63
|
const { script } = await this.getRecommendedAddressObj();
|
|
58
|
-
await tx.addCellDepsOfKnownScripts(this.client, KnownScript.OmniLock);
|
|
64
|
+
await tx.addCellDepsOfKnownScripts(this.client, index_js_4.KnownScript.OmniLock);
|
|
59
65
|
await tx.prepareSighashAllWitness(script, 85, this.client);
|
|
60
66
|
return tx;
|
|
61
67
|
}
|
|
@@ -66,17 +72,18 @@ export class SignerDoge extends Signer {
|
|
|
66
72
|
* @returns A promise that resolves to a signed Transaction object.
|
|
67
73
|
*/
|
|
68
74
|
async signOnlyTransaction(txLike) {
|
|
69
|
-
const tx = Transaction.from(txLike);
|
|
75
|
+
const tx = index_js_3.Transaction.from(txLike);
|
|
70
76
|
const { script } = await this.getRecommendedAddressObj();
|
|
71
77
|
const info = await tx.getSignHashInfo(script, this.client);
|
|
72
78
|
if (!info) {
|
|
73
79
|
return tx;
|
|
74
80
|
}
|
|
75
|
-
const signature = bytesFrom(await this.signMessageRaw(info.message.slice(2)), "base64");
|
|
81
|
+
const signature = (0, index_js_2.bytesFrom)(await this.signMessageRaw(info.message.slice(2)), "base64");
|
|
76
82
|
signature[0] = 31 + ((signature[0] - 27) % 4);
|
|
77
|
-
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
78
|
-
witness.lock = hexFrom(bytesConcat(numToBytes(5 * 4 + signature.length, 4), numToBytes(4 * 4, 4), numToBytes(5 * 4 + signature.length, 4), numToBytes(5 * 4 + signature.length, 4), numToBytes(signature.length, 4), signature));
|
|
83
|
+
const witness = index_js_3.WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
84
|
+
witness.lock = (0, index_js_5.hexFrom)((0, index_js_2.bytesConcat)((0, index_js_6.numToBytes)(5 * 4 + signature.length, 4), (0, index_js_6.numToBytes)(4 * 4, 4), (0, index_js_6.numToBytes)(5 * 4 + signature.length, 4), (0, index_js_6.numToBytes)(5 * 4 + signature.length, 4), (0, index_js_6.numToBytes)(signature.length, 4), signature));
|
|
79
85
|
tx.setWitnessArgsAt(info.position, witness);
|
|
80
86
|
return tx;
|
|
81
87
|
}
|
|
82
88
|
}
|
|
89
|
+
exports.SignerDoge = SignerDoge;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerDogeAddressReadonly = void 0;
|
|
4
|
+
const signerDoge_js_1 = require("./signerDoge.js");
|
|
2
5
|
/**
|
|
3
6
|
* A class extending SignerDoge that provides read-only access to a Doge address.
|
|
4
7
|
* This class does not support signing operations.
|
|
5
8
|
* @public
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
class SignerDogeAddressReadonly extends signerDoge_js_1.SignerDoge {
|
|
8
11
|
/**
|
|
9
12
|
* Creates an instance of SignerDogeAddressReadonly.
|
|
10
13
|
*
|
|
@@ -43,3 +46,4 @@ export class SignerDogeAddressReadonly extends SignerDoge {
|
|
|
43
46
|
return this.address;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
49
|
+
exports.SignerDogeAddressReadonly = SignerDogeAddressReadonly;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerDogePrivateKey = void 0;
|
|
4
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
5
|
+
const bitcoinjs_message_1 = require("bitcoinjs-message");
|
|
6
|
+
const index_js_1 = require("../../bytes/index.js");
|
|
7
|
+
const index_js_2 = require("../../hex/index.js");
|
|
8
|
+
const verify_js_1 = require("../btc/verify.js");
|
|
9
|
+
const signerDoge_js_1 = require("./signerDoge.js");
|
|
7
10
|
/**
|
|
8
11
|
* A class extending SignerDoge that provides access to a Doge address.
|
|
9
12
|
* @public
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
class SignerDogePrivateKey extends signerDoge_js_1.SignerDoge {
|
|
12
15
|
/**
|
|
13
16
|
* Creates an instance of SignerDogePrivateKey
|
|
14
17
|
*
|
|
@@ -18,7 +21,7 @@ export class SignerDogePrivateKey extends SignerDoge {
|
|
|
18
21
|
constructor(client, privateKey, dogeNetwork = 0x1e) {
|
|
19
22
|
super(client);
|
|
20
23
|
this.dogeNetwork = dogeNetwork;
|
|
21
|
-
this.privateKey = bytesFrom(privateKey);
|
|
24
|
+
this.privateKey = (0, index_js_1.bytesFrom)(privateKey);
|
|
22
25
|
if (this.privateKey.length !== 32) {
|
|
23
26
|
throw new Error("Private key must be 32 bytes!");
|
|
24
27
|
}
|
|
@@ -38,7 +41,7 @@ export class SignerDogePrivateKey extends SignerDoge {
|
|
|
38
41
|
return true;
|
|
39
42
|
}
|
|
40
43
|
async getDogePublicKey() {
|
|
41
|
-
return hexFrom(secp256k1.getPublicKey(this.privateKey, true));
|
|
44
|
+
return (0, index_js_2.hexFrom)(secp256k1_1.secp256k1.getPublicKey(this.privateKey, true));
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* Gets the Doge address associated with the signer.
|
|
@@ -51,7 +54,7 @@ export class SignerDogePrivateKey extends SignerDoge {
|
|
|
51
54
|
* ```
|
|
52
55
|
*/
|
|
53
56
|
async getDogeAddress() {
|
|
54
|
-
return btcP2pkhAddressFromPublicKey(await this.getDogePublicKey(), this.dogeNetwork);
|
|
57
|
+
return (0, verify_js_1.btcP2pkhAddressFromPublicKey)(await this.getDogePublicKey(), this.dogeNetwork);
|
|
55
58
|
}
|
|
56
59
|
/**
|
|
57
60
|
* Signs a message and returns signature only.
|
|
@@ -61,8 +64,9 @@ export class SignerDogePrivateKey extends SignerDoge {
|
|
|
61
64
|
* @throws Will throw an error if not implemented.
|
|
62
65
|
*/
|
|
63
66
|
async signMessageRaw(msg) {
|
|
64
|
-
const challenge = typeof msg === "string" ? msg : hexFrom(msg).slice(2);
|
|
65
|
-
const signature = secp256k1.sign(magicHash(challenge, "\x19Dogecoin Signed Message:\n"), this.privateKey);
|
|
66
|
-
return bytesTo(bytesConcat([31 + signature.recovery], signature.toCompactRawBytes()), "base64");
|
|
67
|
+
const challenge = typeof msg === "string" ? msg : (0, index_js_2.hexFrom)(msg).slice(2);
|
|
68
|
+
const signature = secp256k1_1.secp256k1.sign((0, bitcoinjs_message_1.magicHash)(challenge, "\x19Dogecoin Signed Message:\n"), this.privateKey);
|
|
69
|
+
return (0, index_js_1.bytesTo)((0, index_js_1.bytesConcat)([31 + signature.recovery], signature.toCompactRawBytes()), "base64");
|
|
67
70
|
}
|
|
68
71
|
}
|
|
72
|
+
exports.SignerDogePrivateKey = SignerDogePrivateKey;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyMessageDogeEcdsa = verifyMessageDogeEcdsa;
|
|
4
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
5
|
+
const bitcoinjs_message_1 = require("bitcoinjs-message");
|
|
6
|
+
const index_js_1 = require("../../bytes/index.js");
|
|
7
|
+
const index_js_2 = require("../../hex/index.js");
|
|
8
|
+
const verify_js_1 = require("../btc/verify.js");
|
|
6
9
|
/**
|
|
7
10
|
* @public
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
const challenge = typeof message === "string" ? message : hexFrom(message).slice(2);
|
|
11
|
-
const [recoveryBit, ...rawSign] = bytesFrom(signature, "base64");
|
|
12
|
-
const sig = secp256k1.Signature.fromCompact(hexFrom(rawSign).slice(2)).addRecoveryBit(recoveryBit - 31);
|
|
13
|
-
return (btcPublicKeyFromP2pkhAddress(address) ===
|
|
14
|
-
hexFrom(btcEcdsaPublicKeyHash(sig
|
|
15
|
-
.recoverPublicKey(magicHash(challenge, "\x19Dogecoin Signed Message:\n"))
|
|
12
|
+
function verifyMessageDogeEcdsa(message, signature, address) {
|
|
13
|
+
const challenge = typeof message === "string" ? message : (0, index_js_2.hexFrom)(message).slice(2);
|
|
14
|
+
const [recoveryBit, ...rawSign] = (0, index_js_1.bytesFrom)(signature, "base64");
|
|
15
|
+
const sig = secp256k1_1.secp256k1.Signature.fromCompact((0, index_js_2.hexFrom)(rawSign).slice(2)).addRecoveryBit(recoveryBit - 31);
|
|
16
|
+
return ((0, verify_js_1.btcPublicKeyFromP2pkhAddress)(address) ===
|
|
17
|
+
(0, index_js_2.hexFrom)((0, verify_js_1.btcEcdsaPublicKeyHash)(sig
|
|
18
|
+
.recoverPublicKey((0, bitcoinjs_message_1.magicHash)(challenge, "\x19Dogecoin Signed Message:\n"))
|
|
16
19
|
.toHex())));
|
|
17
20
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerAlwaysError = void 0;
|
|
4
|
+
const dummy_js_1 = require("./dummy.js");
|
|
2
5
|
/**
|
|
3
6
|
* @public
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
class SignerAlwaysError extends dummy_js_1.SignerDummy {
|
|
6
9
|
constructor(client, type, message) {
|
|
7
10
|
super(client, type);
|
|
8
11
|
this.message = message;
|
|
@@ -11,3 +14,4 @@ export class SignerAlwaysError extends SignerDummy {
|
|
|
11
14
|
throw new Error(this.message);
|
|
12
15
|
}
|
|
13
16
|
}
|
|
17
|
+
exports.SignerAlwaysError = SignerAlwaysError;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerDummy = void 0;
|
|
4
|
+
const index_js_1 = require("../signer/index.js");
|
|
2
5
|
/**
|
|
3
6
|
* @public
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
class SignerDummy extends index_js_1.Signer {
|
|
6
9
|
get signType() {
|
|
7
|
-
return SignerSignType.Unknown;
|
|
10
|
+
return index_js_1.SignerSignType.Unknown;
|
|
8
11
|
}
|
|
9
12
|
constructor(client, type) {
|
|
10
13
|
super(client);
|
|
@@ -20,3 +23,4 @@ export class SignerDummy extends Signer {
|
|
|
20
23
|
throw new Error("Can't get addresses from SignerDummy");
|
|
21
24
|
}
|
|
22
25
|
}
|
|
26
|
+
exports.SignerDummy = SignerDummy;
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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("./alwaysError.js"), exports);
|
|
18
|
+
__exportStar(require("./dummy.js"), exports);
|
|
19
|
+
__exportStar(require("./openLink.js"), exports);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignerOpenLink = void 0;
|
|
4
|
+
const dummy_js_1 = require("./dummy.js");
|
|
2
5
|
/**
|
|
3
6
|
* @public
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
class SignerOpenLink extends dummy_js_1.SignerDummy {
|
|
6
9
|
constructor(client, type, link) {
|
|
7
10
|
super(client, type);
|
|
8
11
|
this.link = link;
|
|
@@ -11,3 +14,4 @@ export class SignerOpenLink extends SignerDummy {
|
|
|
11
14
|
window.open(this.link, "_blank")?.focus();
|
|
12
15
|
}
|
|
13
16
|
}
|
|
17
|
+
exports.SignerOpenLink = SignerOpenLink;
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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("./signerEvm.js"), exports);
|
|
18
|
+
__exportStar(require("./signerEvmAddressReadonly.js"), exports);
|
|
19
|
+
__exportStar(require("./verify.js"), exports);
|