@ckb-ccc/core 0.1.0-alpha.7 → 0.1.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.
- package/CHANGELOG.md +27 -0
- package/dist/ckb/transactionLumos.d.ts +2 -1
- package/dist/ckb/transactionLumos.d.ts.map +1 -1
- package/dist/client/client.js +1 -1
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +2 -3
- package/dist/signer/btc/verify.d.ts +14 -1
- package/dist/signer/btc/verify.d.ts.map +1 -1
- package/dist/signer/btc/verify.js +22 -1
- package/dist/signer/doge/index.d.ts +5 -0
- package/dist/signer/doge/index.d.ts.map +1 -0
- package/dist/signer/doge/index.js +4 -0
- package/dist/signer/doge/signerDoge.d.ts +52 -0
- package/dist/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist/signer/doge/signerDoge.js +82 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist/signer/doge/signerDogeAddressReadonly.js +45 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist/signer/doge/signerDogePrivateKey.js +68 -0
- package/dist/signer/doge/verify.d.ts +6 -0
- package/dist/signer/doge/verify.d.ts.map +1 -0
- package/dist/signer/doge/verify.js +17 -0
- package/dist/signer/index.d.ts +1 -0
- package/dist/signer/index.d.ts.map +1 -1
- package/dist/signer/index.js +1 -0
- package/dist/signer/nostr/index.d.ts +1 -0
- package/dist/signer/nostr/index.d.ts.map +1 -1
- package/dist/signer/nostr/index.js +1 -0
- package/dist/signer/signer/index.d.ts +4 -2
- package/dist/signer/signer/index.d.ts.map +1 -1
- package/dist/signer/signer/index.js +5 -0
- package/dist.commonjs/address/address.advanced.js +23 -28
- package/dist.commonjs/address/advanced.js +1 -17
- package/dist.commonjs/address/index.js +11 -15
- package/dist.commonjs/advanced.js +2 -31
- package/dist.commonjs/advancedBarrel.js +5 -21
- package/dist.commonjs/barrel.js +12 -41
- package/dist.commonjs/bytes/advanced.js +1 -2
- package/dist.commonjs/bytes/index.js +7 -12
- package/dist.commonjs/ckb/advanced.js +3 -32
- package/dist.commonjs/ckb/index.js +3 -19
- package/dist.commonjs/ckb/molecule.advanced/generated.js +64 -131
- package/dist.commonjs/ckb/molecule.advanced/index.js +2 -19
- package/dist.commonjs/ckb/script.advanced.js +3 -6
- package/dist.commonjs/ckb/script.js +23 -53
- package/dist.commonjs/ckb/transaction.advanced.js +3 -6
- package/dist.commonjs/ckb/transaction.js +122 -163
- package/dist.commonjs/ckb/transactionLumos.d.ts +2 -1
- package/dist.commonjs/ckb/transactionLumos.d.ts.map +1 -1
- package/dist.commonjs/ckb/transactionLumos.js +1 -2
- package/dist.commonjs/client/advanced.js +6 -22
- package/dist.commonjs/client/cache/advanced.js +1 -17
- package/dist.commonjs/client/cache/cache.js +3 -7
- package/dist.commonjs/client/cache/index.js +2 -18
- package/dist.commonjs/client/cache/memory.advanced.js +21 -28
- package/dist.commonjs/client/cache/memory.js +19 -23
- package/dist.commonjs/client/client.js +22 -26
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +22 -25
- package/dist.commonjs/client/clientPublicMainnet.js +8 -15
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +22 -25
- package/dist.commonjs/client/clientPublicTestnet.js +8 -15
- package/dist.commonjs/client/clientTypes.advanced.js +3 -6
- package/dist.commonjs/client/clientTypes.js +29 -43
- package/dist.commonjs/client/index.js +6 -22
- package/dist.commonjs/client/jsonRpc/advanced.js +2 -18
- package/dist.commonjs/client/jsonRpc/index.js +37 -41
- package/dist.commonjs/client/jsonRpc/transformers.js +57 -61
- package/dist.commonjs/client/jsonRpc/types.js +1 -2
- package/dist.commonjs/client/transports/advanced.js +8 -25
- package/dist.commonjs/client/transports/http.js +1 -5
- package/dist.commonjs/client/transports/transport.js +1 -2
- package/dist.commonjs/client/transports/webSocket.js +3 -10
- package/dist.commonjs/fixedPoint/index.js +4 -9
- package/dist.commonjs/hasher/advanced.js +1 -4
- package/dist.commonjs/hasher/hasher.js +1 -2
- package/dist.commonjs/hasher/hasherCkb.js +14 -20
- package/dist.commonjs/hasher/hasherKeecak256.js +7 -11
- package/dist.commonjs/hasher/index.js +3 -19
- package/dist.commonjs/hex/index.js +3 -6
- package/dist.commonjs/index.js +2 -31
- package/dist.commonjs/keystore/index.js +21 -25
- package/dist.commonjs/molecule/codec.js +48 -63
- package/dist.commonjs/molecule/index.js +2 -18
- package/dist.commonjs/molecule/predefined.js +77 -103
- package/dist.commonjs/num/index.js +17 -29
- package/dist.commonjs/signer/btc/index.js +3 -19
- package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/signerBtc.js +20 -25
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +4 -8
- package/dist.commonjs/signer/btc/verify.d.ts +14 -1
- package/dist.commonjs/signer/btc/verify.d.ts.map +1 -1
- package/dist.commonjs/signer/btc/verify.js +29 -11
- package/dist.commonjs/signer/ckb/index.js +5 -21
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +16 -20
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +20 -24
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +8 -12
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +12 -16
- package/dist.commonjs/signer/ckb/verifyJoyId.js +5 -8
- package/dist.commonjs/signer/doge/index.d.ts +5 -0
- package/dist.commonjs/signer/doge/index.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/index.js +4 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDoge.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDoge.js +82 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts +41 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogeAddressReadonly.js +45 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts +52 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/signerDogePrivateKey.js +68 -0
- package/dist.commonjs/signer/doge/verify.d.ts +6 -0
- package/dist.commonjs/signer/doge/verify.d.ts.map +1 -0
- package/dist.commonjs/signer/doge/verify.js +17 -0
- package/dist.commonjs/signer/dummy/alwaysError.js +2 -6
- package/dist.commonjs/signer/dummy/dummy.js +3 -7
- package/dist.commonjs/signer/dummy/index.js +3 -19
- package/dist.commonjs/signer/dummy/openLink.js +2 -6
- package/dist.commonjs/signer/evm/index.js +3 -19
- package/dist.commonjs/signer/evm/signerEvm.js +31 -35
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +4 -8
- package/dist.commonjs/signer/evm/verify.js +4 -7
- package/dist.commonjs/signer/index.d.ts +1 -0
- package/dist.commonjs/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/index.js +7 -22
- package/dist.commonjs/signer/nostr/index.d.ts +1 -0
- package/dist.commonjs/signer/nostr/index.d.ts.map +1 -1
- package/dist.commonjs/signer/nostr/index.js +2 -17
- package/dist.commonjs/signer/nostr/signerNostr.js +21 -25
- package/dist.commonjs/signer/nostr/verify.js +12 -16
- package/dist.commonjs/signer/signer/index.d.ts +4 -2
- package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
- package/dist.commonjs/signer/signer/index.js +22 -23
- package/dist.commonjs/utils/index.js +6 -12
- package/package.json +3 -1
- package/src/ckb/transactionLumos.ts +2 -1
- package/src/client/client.ts +1 -1
- package/src/signer/btc/signerBtc.ts +2 -3
- package/src/signer/btc/verify.ts +31 -2
- package/src/signer/doge/index.ts +4 -0
- package/src/signer/doge/signerDoge.ts +116 -0
- package/src/signer/doge/signerDogeAddressReadonly.ts +52 -0
- package/src/signer/doge/signerDogePrivateKey.ts +97 -0
- package/src/signer/doge/verify.ts +38 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/nostr/index.ts +1 -0
- package/src/signer/signer/index.ts +9 -0
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const verify_js_1 = require("../evm/verify.js");
|
|
8
|
-
const verify_js_2 = require("../nostr/verify.js");
|
|
1
|
+
import { verifyMessageBtcEcdsa } from "../btc/index.js";
|
|
2
|
+
import { verifyMessageCkbSecp256k1 } from "../ckb/verifyCkbSecp256k1.js";
|
|
3
|
+
import { verifyMessageJoyId } from "../ckb/verifyJoyId.js";
|
|
4
|
+
import { verifyMessageDogeEcdsa } from "../doge/verify.js";
|
|
5
|
+
import { verifyMessageEvmPersonal } from "../evm/verify.js";
|
|
6
|
+
import { verifyMessageNostrEvent } from "../nostr/verify.js";
|
|
9
7
|
/**
|
|
10
8
|
* @public
|
|
11
9
|
*/
|
|
12
|
-
var SignerSignType;
|
|
10
|
+
export var SignerSignType;
|
|
13
11
|
(function (SignerSignType) {
|
|
14
12
|
SignerSignType["Unknown"] = "Unknown";
|
|
15
13
|
SignerSignType["BtcEcdsa"] = "BtcEcdsa";
|
|
@@ -17,35 +15,36 @@ var SignerSignType;
|
|
|
17
15
|
SignerSignType["JoyId"] = "JoyId";
|
|
18
16
|
SignerSignType["NostrEvent"] = "NostrEvent";
|
|
19
17
|
SignerSignType["CkbSecp256k1"] = "CkbSecp256k1";
|
|
20
|
-
|
|
18
|
+
SignerSignType["DogeEcdsa"] = "DogeEcdsa";
|
|
19
|
+
})(SignerSignType || (SignerSignType = {}));
|
|
21
20
|
/**
|
|
22
21
|
* An enumeration of signer display types in wallet.
|
|
23
22
|
* @public
|
|
24
23
|
*/
|
|
25
|
-
var SignerType;
|
|
24
|
+
export var SignerType;
|
|
26
25
|
(function (SignerType) {
|
|
27
26
|
SignerType["EVM"] = "EVM";
|
|
28
27
|
SignerType["BTC"] = "BTC";
|
|
29
28
|
SignerType["CKB"] = "CKB";
|
|
30
29
|
SignerType["Nostr"] = "Nostr";
|
|
31
|
-
|
|
30
|
+
SignerType["Doge"] = "Doge";
|
|
31
|
+
})(SignerType || (SignerType = {}));
|
|
32
32
|
/**
|
|
33
33
|
* @public
|
|
34
34
|
*/
|
|
35
|
-
class Signature {
|
|
35
|
+
export class Signature {
|
|
36
36
|
constructor(signature, identity, signType) {
|
|
37
37
|
this.signature = signature;
|
|
38
38
|
this.identity = identity;
|
|
39
39
|
this.signType = signType;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
exports.Signature = Signature;
|
|
43
42
|
/**
|
|
44
43
|
* An abstract class representing a generic signer.
|
|
45
44
|
* This class provides methods to connect, get addresses, and sign transactions.
|
|
46
45
|
* @public
|
|
47
46
|
*/
|
|
48
|
-
class Signer {
|
|
47
|
+
export class Signer {
|
|
49
48
|
constructor(client_) {
|
|
50
49
|
this.client_ = client_;
|
|
51
50
|
}
|
|
@@ -68,15 +67,17 @@ class Signer {
|
|
|
68
67
|
static async verifyMessage(message, signature) {
|
|
69
68
|
switch (signature.signType) {
|
|
70
69
|
case SignerSignType.EvmPersonal:
|
|
71
|
-
return
|
|
70
|
+
return verifyMessageEvmPersonal(message, signature.signature, signature.identity);
|
|
72
71
|
case SignerSignType.BtcEcdsa:
|
|
73
|
-
return
|
|
72
|
+
return verifyMessageBtcEcdsa(message, signature.signature, signature.identity);
|
|
74
73
|
case SignerSignType.JoyId:
|
|
75
|
-
return
|
|
74
|
+
return verifyMessageJoyId(message, signature.signature, signature.identity);
|
|
76
75
|
case SignerSignType.NostrEvent:
|
|
77
|
-
return
|
|
76
|
+
return verifyMessageNostrEvent(message, signature.signature, signature.identity);
|
|
78
77
|
case SignerSignType.CkbSecp256k1:
|
|
79
|
-
return
|
|
78
|
+
return verifyMessageCkbSecp256k1(message, signature.signature, signature.identity);
|
|
79
|
+
case SignerSignType.DogeEcdsa:
|
|
80
|
+
return verifyMessageDogeEcdsa(message, signature.signature, signature.identity);
|
|
80
81
|
case SignerSignType.Unknown:
|
|
81
82
|
throw new Error("Unknown signer sign type");
|
|
82
83
|
}
|
|
@@ -261,15 +262,13 @@ class Signer {
|
|
|
261
262
|
throw Error("Signer.signOnlyTransaction not implemented");
|
|
262
263
|
}
|
|
263
264
|
}
|
|
264
|
-
exports.Signer = Signer;
|
|
265
265
|
/**
|
|
266
266
|
* A class representing information about a signer, including its type and the signer instance.
|
|
267
267
|
* @public
|
|
268
268
|
*/
|
|
269
|
-
class SignerInfo {
|
|
269
|
+
export class SignerInfo {
|
|
270
270
|
constructor(name, signer) {
|
|
271
271
|
this.name = name;
|
|
272
272
|
this.signer = signer;
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
|
-
exports.SignerInfo = SignerInfo;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
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");
|
|
1
|
+
import { numFrom } from "../num/index.js";
|
|
8
2
|
/**
|
|
9
3
|
* A type safe way to apply a transformer on a value if it's not empty.
|
|
10
4
|
* @public
|
|
@@ -13,7 +7,7 @@ const index_js_1 = require("../num/index.js");
|
|
|
13
7
|
* @param value - The value to be transformed.
|
|
14
8
|
* @returns If the value is empty, it becomes undefined. Otherwise it will be transformed.
|
|
15
9
|
*/
|
|
16
|
-
function apply(transformer, value) {
|
|
10
|
+
export function apply(transformer, value) {
|
|
17
11
|
if (value == null) {
|
|
18
12
|
return undefined;
|
|
19
13
|
}
|
|
@@ -28,7 +22,7 @@ function apply(transformer, value) {
|
|
|
28
22
|
* @param init - The initial value.
|
|
29
23
|
* @returns The accumulated result.
|
|
30
24
|
*/
|
|
31
|
-
async function reduceAsync(values, accumulator, init) {
|
|
25
|
+
export async function reduceAsync(values, accumulator, init) {
|
|
32
26
|
if (init === undefined) {
|
|
33
27
|
if (values.length === 0) {
|
|
34
28
|
throw new TypeError("Reduce of empty array with no initial value");
|
|
@@ -38,12 +32,12 @@ async function reduceAsync(values, accumulator, init) {
|
|
|
38
32
|
}
|
|
39
33
|
return values.reduce((current, b, i, array) => current.then((v) => Promise.resolve(accumulator(v, b, i, array)).then((r) => r ?? v)), Promise.resolve(init));
|
|
40
34
|
}
|
|
41
|
-
function sleep(ms) {
|
|
42
|
-
return new Promise((resolve) => setTimeout(resolve, Number(
|
|
35
|
+
export function sleep(ms) {
|
|
36
|
+
return new Promise((resolve) => setTimeout(resolve, Number(numFrom(ms))));
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
39
|
* @public
|
|
46
40
|
*/
|
|
47
|
-
function isWebview(userAgent) {
|
|
41
|
+
export function isWebview(userAgent) {
|
|
48
42
|
return /webview|wv|ip((?!.*Safari)|(?=.*like Safari))/i.test(userAgent);
|
|
49
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/core",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Core of CCC - CKBer's Codebase",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git://github.com/ckb-devrel/ccc.git"
|
|
12
12
|
},
|
|
13
|
+
"type": "module",
|
|
13
14
|
"main": "./dist.commonjs/index.js",
|
|
14
15
|
"module": "./dist/index.js",
|
|
15
16
|
"exports": {
|
|
@@ -59,6 +60,7 @@
|
|
|
59
60
|
"abort-controller": "^3.0.0",
|
|
60
61
|
"bech32": "^2.0.0",
|
|
61
62
|
"bitcoinjs-message": "^2.2.0",
|
|
63
|
+
"bs58check": "^4.0.0",
|
|
62
64
|
"buffer": "^6.0.3",
|
|
63
65
|
"cross-fetch": "^4.0.0",
|
|
64
66
|
"ethers": "^6.13.1",
|
package/src/client/client.ts
CHANGED
|
@@ -517,7 +517,7 @@ export abstract class Client {
|
|
|
517
517
|
async waitTransaction(
|
|
518
518
|
txHash: HexLike,
|
|
519
519
|
confirmations: number = 0,
|
|
520
|
-
timeout: number =
|
|
520
|
+
timeout: number = 60000,
|
|
521
521
|
interval: number = 2000,
|
|
522
522
|
): Promise<ClientTransactionResponse | undefined> {
|
|
523
523
|
const startTime = Date.now();
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
2
|
-
import { sha256 } from "@noble/hashes/sha256";
|
|
3
1
|
import { Address } from "../../address/index.js";
|
|
4
2
|
import { bytesConcat, bytesFrom } from "../../bytes/index.js";
|
|
5
3
|
import { Transaction, TransactionLike, WitnessArgs } from "../../ckb/index.js";
|
|
@@ -7,6 +5,7 @@ import { KnownScript } from "../../client/index.js";
|
|
|
7
5
|
import { HexLike, hexFrom } from "../../hex/index.js";
|
|
8
6
|
import { numToBytes } from "../../num/index.js";
|
|
9
7
|
import { Signer, SignerSignType, SignerType } from "../signer/index.js";
|
|
8
|
+
import { btcEcdsaPublicKeyHash } from "./verify.js";
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* An abstract class extending the Signer class for Bitcoin-like signing operations.
|
|
@@ -62,7 +61,7 @@ export abstract class SignerBtc extends Signer {
|
|
|
62
61
|
*/
|
|
63
62
|
async getAddressObjs(): Promise<Address[]> {
|
|
64
63
|
const publicKey = await this.getBtcPublicKey();
|
|
65
|
-
const hash =
|
|
64
|
+
const hash = btcEcdsaPublicKeyHash(publicKey);
|
|
66
65
|
|
|
67
66
|
return [
|
|
68
67
|
await Address.fromKnownScript(
|
package/src/signer/btc/verify.ts
CHANGED
|
@@ -1,7 +1,36 @@
|
|
|
1
1
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
2
|
+
import { ripemd160 } from "@noble/hashes/ripemd160";
|
|
3
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
2
4
|
import { magicHash } from "bitcoinjs-message";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
+
import bs58check from "bs58check";
|
|
6
|
+
import { Bytes, BytesLike, bytesConcat, bytesFrom } from "../../bytes/index.js";
|
|
7
|
+
import { Hex, hexFrom } from "../../hex/index.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export function btcEcdsaPublicKeyHash(publicKey: BytesLike): Bytes {
|
|
13
|
+
return ripemd160(sha256(bytesFrom(publicKey)));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export function btcP2pkhAddressFromPublicKey(
|
|
20
|
+
publicKey: BytesLike,
|
|
21
|
+
network: number,
|
|
22
|
+
): string {
|
|
23
|
+
return bs58check.encode(
|
|
24
|
+
bytesConcat([network], btcEcdsaPublicKeyHash(publicKey)),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export function btcPublicKeyFromP2pkhAddress(address: string): Hex {
|
|
32
|
+
return hexFrom(bs58check.decode(address).slice(1));
|
|
33
|
+
}
|
|
5
34
|
|
|
6
35
|
/**
|
|
7
36
|
* @public
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import bs58check from "bs58check";
|
|
2
|
+
import { Address } from "../../address/index.js";
|
|
3
|
+
import { bytesConcat, bytesFrom } from "../../bytes/index.js";
|
|
4
|
+
import { Transaction, TransactionLike, WitnessArgs } from "../../ckb/index.js";
|
|
5
|
+
import { KnownScript } from "../../client/index.js";
|
|
6
|
+
import { hexFrom } from "../../hex/index.js";
|
|
7
|
+
import { numToBytes } from "../../num/index.js";
|
|
8
|
+
import { Signer, SignerSignType, SignerType } from "../signer/index.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An abstract class extending the Signer class for Dogecoin-like signing operations.
|
|
12
|
+
* This class provides methods to get Doge account, public key, and internal address,
|
|
13
|
+
* as well as signing transactions.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export abstract class SignerDoge extends Signer {
|
|
17
|
+
get type(): SignerType {
|
|
18
|
+
return SignerType.Doge;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get signType(): SignerSignType {
|
|
22
|
+
return SignerSignType.DogeEcdsa;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets the Doge address associated with the signer.
|
|
27
|
+
*
|
|
28
|
+
* @returns A promise that resolves to a string representing the Doge account.
|
|
29
|
+
*/
|
|
30
|
+
abstract getDogeAddress(): Promise<string>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Gets the internal address, which is the Doge account in this case.
|
|
34
|
+
*
|
|
35
|
+
* @returns A promise that resolves to a string representing the internal address.
|
|
36
|
+
*/
|
|
37
|
+
async getInternalAddress(): Promise<string> {
|
|
38
|
+
return this.getDogeAddress();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Gets the identity, which is the Doge address in this case.
|
|
43
|
+
*
|
|
44
|
+
* @returns A promise that resolves to a string representing the identity
|
|
45
|
+
*/
|
|
46
|
+
async getIdentity(): Promise<string> {
|
|
47
|
+
return this.getDogeAddress();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
52
|
+
*
|
|
53
|
+
* @returns A promise that resolves to an array of Address objects.
|
|
54
|
+
*/
|
|
55
|
+
async getAddressObjs(): Promise<Address[]> {
|
|
56
|
+
const hash = bs58check.decode(await this.getDogeAddress()).slice(1);
|
|
57
|
+
|
|
58
|
+
return [
|
|
59
|
+
await Address.fromKnownScript(
|
|
60
|
+
this.client,
|
|
61
|
+
KnownScript.OmniLock,
|
|
62
|
+
hexFrom([0x05, ...hash, 0x00]),
|
|
63
|
+
),
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
|
|
69
|
+
*
|
|
70
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
71
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
72
|
+
*/
|
|
73
|
+
async prepareTransaction(txLike: TransactionLike): Promise<Transaction> {
|
|
74
|
+
const tx = Transaction.from(txLike);
|
|
75
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
76
|
+
await tx.addCellDepsOfKnownScripts(this.client, KnownScript.OmniLock);
|
|
77
|
+
await tx.prepareSighashAllWitness(script, 85, this.client);
|
|
78
|
+
return tx;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Signs a transaction without modifying it.
|
|
83
|
+
*
|
|
84
|
+
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
85
|
+
* @returns A promise that resolves to a signed Transaction object.
|
|
86
|
+
*/
|
|
87
|
+
async signOnlyTransaction(txLike: TransactionLike): Promise<Transaction> {
|
|
88
|
+
const tx = Transaction.from(txLike);
|
|
89
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
90
|
+
const info = await tx.getSignHashInfo(script, this.client);
|
|
91
|
+
if (!info) {
|
|
92
|
+
return tx;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const signature = bytesFrom(
|
|
96
|
+
await this.signMessageRaw(info.message.slice(2)),
|
|
97
|
+
"base64",
|
|
98
|
+
);
|
|
99
|
+
signature[0] = 31 + ((signature[0] - 27) % 4);
|
|
100
|
+
|
|
101
|
+
const witness = WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
102
|
+
witness.lock = hexFrom(
|
|
103
|
+
bytesConcat(
|
|
104
|
+
numToBytes(5 * 4 + signature.length, 4),
|
|
105
|
+
numToBytes(4 * 4, 4),
|
|
106
|
+
numToBytes(5 * 4 + signature.length, 4),
|
|
107
|
+
numToBytes(5 * 4 + signature.length, 4),
|
|
108
|
+
numToBytes(signature.length, 4),
|
|
109
|
+
signature,
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
tx.setWitnessArgsAt(info.position, witness);
|
|
114
|
+
return tx;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Client } from "../../client/index.js";
|
|
2
|
+
import { SignerDoge } from "./signerDoge.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A class extending SignerDoge that provides read-only access to a Doge address.
|
|
6
|
+
* This class does not support signing operations.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export class SignerDogeAddressReadonly extends SignerDoge {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of SignerDogeAddressReadonly.
|
|
12
|
+
*
|
|
13
|
+
* @param client - The client instance used for communication.
|
|
14
|
+
* @param address - The Doge address with the signer.
|
|
15
|
+
*/
|
|
16
|
+
constructor(
|
|
17
|
+
client: Client,
|
|
18
|
+
private readonly address: string,
|
|
19
|
+
) {
|
|
20
|
+
super(client);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Connects to the client. This implementation does nothing as the class is read-only.
|
|
25
|
+
*
|
|
26
|
+
* @returns A promise that resolves when the connection is complete.
|
|
27
|
+
*/
|
|
28
|
+
async connect(): Promise<void> {}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Check if the signer is connected.
|
|
32
|
+
*
|
|
33
|
+
* @returns A promise that resolves the connection status.
|
|
34
|
+
*/
|
|
35
|
+
async isConnected(): Promise<boolean> {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the Doge address associated with the signer.
|
|
41
|
+
*
|
|
42
|
+
* @returns A promise that resolves to a string representing the Doge address.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const account = await signer.getDogeAddress(); // Outputs the Doge address
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
async getDogeAddress(): Promise<string> {
|
|
50
|
+
return this.address;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
2
|
+
import { magicHash } from "bitcoinjs-message";
|
|
3
|
+
import {
|
|
4
|
+
Bytes,
|
|
5
|
+
bytesConcat,
|
|
6
|
+
bytesFrom,
|
|
7
|
+
BytesLike,
|
|
8
|
+
bytesTo,
|
|
9
|
+
} from "../../bytes/index.js";
|
|
10
|
+
import { Client } from "../../client/index.js";
|
|
11
|
+
import { Hex, hexFrom } from "../../hex/index.js";
|
|
12
|
+
import { btcP2pkhAddressFromPublicKey } from "../btc/verify.js";
|
|
13
|
+
import { SignerDoge } from "./signerDoge.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A class extending SignerDoge that provides access to a Doge address.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export class SignerDogePrivateKey extends SignerDoge {
|
|
20
|
+
private readonly privateKey: Bytes;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of SignerDogePrivateKey
|
|
24
|
+
*
|
|
25
|
+
* @param client - The client instance used for communication.
|
|
26
|
+
* @param privateKey - The Doge private key with the signer.
|
|
27
|
+
*/
|
|
28
|
+
constructor(
|
|
29
|
+
client: Client,
|
|
30
|
+
privateKey: BytesLike,
|
|
31
|
+
public readonly dogeNetwork = 0x1e,
|
|
32
|
+
) {
|
|
33
|
+
super(client);
|
|
34
|
+
this.privateKey = bytesFrom(privateKey);
|
|
35
|
+
if (this.privateKey.length !== 32) {
|
|
36
|
+
throw new Error("Private key must be 32 bytes!");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Connects to the client. This implementation does nothing as the class is always connected.
|
|
42
|
+
*
|
|
43
|
+
* @returns A promise that resolves when the connection is complete.
|
|
44
|
+
*/
|
|
45
|
+
async connect(): Promise<void> {}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Check if the signer is connected.
|
|
49
|
+
*
|
|
50
|
+
* @returns A promise that resolves the connection status.
|
|
51
|
+
*/
|
|
52
|
+
async isConnected(): Promise<boolean> {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async getDogePublicKey(): Promise<Hex> {
|
|
57
|
+
return hexFrom(secp256k1.getPublicKey(this.privateKey, true));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Gets the Doge address associated with the signer.
|
|
62
|
+
*
|
|
63
|
+
* @returns A promise that resolves to a string representing the Doge address.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const account = await signer.getDogeAddress(); // Outputs the Doge address
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
async getDogeAddress(): Promise<string> {
|
|
71
|
+
return btcP2pkhAddressFromPublicKey(
|
|
72
|
+
await this.getDogePublicKey(),
|
|
73
|
+
this.dogeNetwork,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Signs a message and returns signature only.
|
|
79
|
+
*
|
|
80
|
+
* @param msg - The message to sign, as a string or BytesLike object.
|
|
81
|
+
* @returns A promise that resolves to the signature as a string.
|
|
82
|
+
* @throws Will throw an error if not implemented.
|
|
83
|
+
*/
|
|
84
|
+
async signMessageRaw(msg: string | BytesLike): Promise<string> {
|
|
85
|
+
const challenge = typeof msg === "string" ? msg : hexFrom(msg).slice(2);
|
|
86
|
+
|
|
87
|
+
const signature = secp256k1.sign(
|
|
88
|
+
magicHash(challenge, "\x19Dogecoin Signed Message:\n"),
|
|
89
|
+
this.privateKey,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return bytesTo(
|
|
93
|
+
bytesConcat([31 + signature.recovery], signature.toCompactRawBytes()),
|
|
94
|
+
"base64",
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
2
|
+
import { magicHash } from "bitcoinjs-message";
|
|
3
|
+
import { bytesFrom, BytesLike } from "../../bytes/index.js";
|
|
4
|
+
import { hexFrom } from "../../hex/index.js";
|
|
5
|
+
import {
|
|
6
|
+
btcEcdsaPublicKeyHash,
|
|
7
|
+
btcPublicKeyFromP2pkhAddress,
|
|
8
|
+
} from "../btc/verify.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export function verifyMessageDogeEcdsa(
|
|
14
|
+
message: string | BytesLike,
|
|
15
|
+
signature: string,
|
|
16
|
+
address: string,
|
|
17
|
+
): boolean {
|
|
18
|
+
const challenge =
|
|
19
|
+
typeof message === "string" ? message : hexFrom(message).slice(2);
|
|
20
|
+
const [recoveryBit, ...rawSign] = bytesFrom(signature, "base64");
|
|
21
|
+
|
|
22
|
+
const sig = secp256k1.Signature.fromCompact(
|
|
23
|
+
hexFrom(rawSign).slice(2),
|
|
24
|
+
).addRecoveryBit(recoveryBit - 31);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
btcPublicKeyFromP2pkhAddress(address) ===
|
|
28
|
+
hexFrom(
|
|
29
|
+
btcEcdsaPublicKeyHash(
|
|
30
|
+
sig
|
|
31
|
+
.recoverPublicKey(
|
|
32
|
+
magicHash(challenge, "\x19Dogecoin Signed Message:\n"),
|
|
33
|
+
)
|
|
34
|
+
.toHex(),
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
}
|
package/src/signer/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { Num } from "../../num/index.js";
|
|
|
12
12
|
import { verifyMessageBtcEcdsa } from "../btc/index.js";
|
|
13
13
|
import { verifyMessageCkbSecp256k1 } from "../ckb/verifyCkbSecp256k1.js";
|
|
14
14
|
import { verifyMessageJoyId } from "../ckb/verifyJoyId.js";
|
|
15
|
+
import { verifyMessageDogeEcdsa } from "../doge/verify.js";
|
|
15
16
|
import { verifyMessageEvmPersonal } from "../evm/verify.js";
|
|
16
17
|
import { verifyMessageNostrEvent } from "../nostr/verify.js";
|
|
17
18
|
|
|
@@ -25,6 +26,7 @@ export enum SignerSignType {
|
|
|
25
26
|
JoyId = "JoyId",
|
|
26
27
|
NostrEvent = "NostrEvent",
|
|
27
28
|
CkbSecp256k1 = "CkbSecp256k1",
|
|
29
|
+
DogeEcdsa = "DogeEcdsa",
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -36,6 +38,7 @@ export enum SignerType {
|
|
|
36
38
|
BTC = "BTC",
|
|
37
39
|
CKB = "CKB",
|
|
38
40
|
Nostr = "Nostr",
|
|
41
|
+
Doge = "Doge",
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
@@ -141,6 +144,12 @@ export abstract class Signer {
|
|
|
141
144
|
signature.signature,
|
|
142
145
|
signature.identity,
|
|
143
146
|
);
|
|
147
|
+
case SignerSignType.DogeEcdsa:
|
|
148
|
+
return verifyMessageDogeEcdsa(
|
|
149
|
+
message,
|
|
150
|
+
signature.signature,
|
|
151
|
+
signature.identity,
|
|
152
|
+
);
|
|
144
153
|
case SignerSignType.Unknown:
|
|
145
154
|
throw new Error("Unknown signer sign type");
|
|
146
155
|
}
|