@ckb-ccc/core 0.1.0-alpha.6 → 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 +34 -0
- package/dist/barrel.d.ts +1 -0
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -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/molecule/codec.d.ts +118 -0
- package/dist/molecule/codec.d.ts.map +1 -0
- package/dist/molecule/codec.js +446 -0
- package/dist/molecule/index.d.ts +3 -0
- package/dist/molecule/index.d.ts.map +1 -0
- package/dist/molecule/index.js +2 -0
- package/dist/molecule/predefined.d.ts +52 -0
- package/dist/molecule/predefined.d.ts.map +1 -0
- package/dist/molecule/predefined.js +95 -0
- 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.d.ts +1 -0
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +12 -27
- 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.d.ts +118 -0
- package/dist.commonjs/molecule/codec.d.ts.map +1 -0
- package/dist.commonjs/molecule/codec.js +446 -0
- package/dist.commonjs/molecule/index.d.ts +3 -0
- package/dist.commonjs/molecule/index.d.ts.map +1 -0
- package/dist.commonjs/molecule/index.js +2 -0
- package/dist.commonjs/molecule/predefined.d.ts +52 -0
- package/dist.commonjs/molecule/predefined.d.ts.map +1 -0
- package/dist.commonjs/molecule/predefined.js +95 -0
- 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/barrel.ts +1 -0
- package/src/ckb/transactionLumos.ts +2 -1
- package/src/client/client.ts +1 -1
- package/src/molecule/codec.ts +610 -0
- package/src/molecule/index.ts +2 -0
- package/src/molecule/predefined.ts +114 -0
- 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
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { bytesFrom, bytesTo } from "../bytes/index.js";
|
|
2
|
+
import * as ckb from "../ckb/index.js";
|
|
3
|
+
import { Hex, hexFrom, HexLike } from "../hex/index.js";
|
|
4
|
+
import {
|
|
5
|
+
byteVec,
|
|
6
|
+
Codec,
|
|
7
|
+
option,
|
|
8
|
+
struct,
|
|
9
|
+
table,
|
|
10
|
+
uint,
|
|
11
|
+
uintNumber,
|
|
12
|
+
vector,
|
|
13
|
+
} from "./codec.js";
|
|
14
|
+
|
|
15
|
+
export const Uint8 = uintNumber(1, true);
|
|
16
|
+
export const Uint16LE = uintNumber(2, true);
|
|
17
|
+
export const Uint16BE = uintNumber(2);
|
|
18
|
+
export const Uint16 = Uint16LE;
|
|
19
|
+
export const Uint32LE = uintNumber(4, true);
|
|
20
|
+
export const Uint32BE = uintNumber(4);
|
|
21
|
+
export const Uint32 = Uint32LE;
|
|
22
|
+
export const Uint64LE = uint(8, true);
|
|
23
|
+
export const Uint64BE = uint(8);
|
|
24
|
+
export const Uint64 = Uint64LE;
|
|
25
|
+
export const Uint128LE = uint(16, true);
|
|
26
|
+
export const Uint128BE = uint(16);
|
|
27
|
+
export const Uint128 = Uint128LE;
|
|
28
|
+
export const Uint256LE = uint(32, true);
|
|
29
|
+
export const Uint256BE = uint(32);
|
|
30
|
+
export const Uint256 = Uint256LE;
|
|
31
|
+
export const Uint512LE = uint(64, true);
|
|
32
|
+
export const Uint512BE = uint(64);
|
|
33
|
+
export const Uint512 = Uint512LE;
|
|
34
|
+
|
|
35
|
+
export const Uint8Opt = option(Uint8);
|
|
36
|
+
export const Uint16Opt = option(Uint16);
|
|
37
|
+
export const Uint32Opt = option(Uint32);
|
|
38
|
+
export const Uint64Opt = option(Uint64);
|
|
39
|
+
export const Uint128Opt = option(Uint128);
|
|
40
|
+
export const Uint256Opt = option(Uint256);
|
|
41
|
+
export const Uint512Opt = option(Uint512);
|
|
42
|
+
|
|
43
|
+
export const Bytes: Codec<HexLike, Hex> = byteVec({
|
|
44
|
+
encode: (value) => bytesFrom(value),
|
|
45
|
+
decode: (buffer) => hexFrom(buffer),
|
|
46
|
+
});
|
|
47
|
+
export const BytesOpt = option(Bytes);
|
|
48
|
+
export const BytesVec = vector(Bytes);
|
|
49
|
+
|
|
50
|
+
export const Byte32: Codec<HexLike, Hex> = Codec.from({
|
|
51
|
+
byteLength: 32,
|
|
52
|
+
encode: (value) => bytesFrom(value),
|
|
53
|
+
decode: (buffer) => hexFrom(buffer),
|
|
54
|
+
});
|
|
55
|
+
export const Byte32Opt = option(Byte32);
|
|
56
|
+
export const Byte32Vec = vector(Byte32);
|
|
57
|
+
|
|
58
|
+
export const String = byteVec({
|
|
59
|
+
encode: (value: string) => bytesFrom(value, "utf8"),
|
|
60
|
+
decode: (buffer) => bytesTo(buffer, "utf8"),
|
|
61
|
+
});
|
|
62
|
+
export const StringVec = vector(String);
|
|
63
|
+
export const StringOpt = option(String);
|
|
64
|
+
|
|
65
|
+
export const Hash = Byte32;
|
|
66
|
+
export const HashType: Codec<ckb.HashTypeLike, ckb.HashType> = Codec.from({
|
|
67
|
+
byteLength: 1,
|
|
68
|
+
encode: ckb.hashTypeToBytes,
|
|
69
|
+
decode: ckb.hashTypeFromBytes,
|
|
70
|
+
});
|
|
71
|
+
export const Script: Codec<ckb.ScriptLike, ckb.Script> = table({
|
|
72
|
+
codeHash: Hash,
|
|
73
|
+
hashType: HashType,
|
|
74
|
+
args: Bytes,
|
|
75
|
+
}).map({ outMap: ckb.Script.from });
|
|
76
|
+
export const ScriptOpt = option(Script);
|
|
77
|
+
|
|
78
|
+
export const OutPoint: Codec<ckb.OutPointLike, ckb.OutPoint> = struct({
|
|
79
|
+
txHash: Hash,
|
|
80
|
+
index: Uint32,
|
|
81
|
+
}).map({ outMap: ckb.OutPoint.from });
|
|
82
|
+
export const CellInput: Codec<ckb.CellInputLike, ckb.CellInput> = struct({
|
|
83
|
+
previousOutput: OutPoint,
|
|
84
|
+
since: Uint64,
|
|
85
|
+
}).map({ outMap: ckb.CellInput.from });
|
|
86
|
+
export const CellInputVec = vector(CellInput);
|
|
87
|
+
|
|
88
|
+
export const CellOutput: Codec<ckb.CellOutputLike, ckb.CellOutput> = table({
|
|
89
|
+
capacity: Uint64,
|
|
90
|
+
lock: Script,
|
|
91
|
+
type: ScriptOpt,
|
|
92
|
+
}).map({ outMap: ckb.CellOutput.from });
|
|
93
|
+
export const CellOutputVec = vector(CellOutput);
|
|
94
|
+
|
|
95
|
+
export const DepType: Codec<ckb.DepTypeLike, ckb.DepType> = Codec.from({
|
|
96
|
+
byteLength: 1,
|
|
97
|
+
encode: ckb.depTypeToBytes,
|
|
98
|
+
decode: ckb.depTypeFromBytes,
|
|
99
|
+
});
|
|
100
|
+
export const CellDep: Codec<ckb.CellDepLike, ckb.CellDep> = struct({
|
|
101
|
+
outPoint: OutPoint,
|
|
102
|
+
depType: DepType,
|
|
103
|
+
}).map({ outMap: ckb.CellDep.from });
|
|
104
|
+
export const CellDepVec = vector(CellDep);
|
|
105
|
+
|
|
106
|
+
export const Transaction: Codec<ckb.TransactionLike, ckb.Transaction> = table({
|
|
107
|
+
version: Uint32,
|
|
108
|
+
cellDeps: CellDepVec,
|
|
109
|
+
headerDeps: Byte32Vec,
|
|
110
|
+
inputs: CellInputVec,
|
|
111
|
+
outputs: CellOutputVec,
|
|
112
|
+
outputsData: BytesVec,
|
|
113
|
+
witnesses: BytesVec,
|
|
114
|
+
}).map({ outMap: ckb.Transaction.from });
|
|
@@ -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
|
}
|