@ckb-ccc/core 0.0.10-alpha.4 → 0.0.10-alpha.5
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/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +1 -2
- package/dist.commonjs/address/address.advanced.d.ts +24 -29
- package/dist.commonjs/address/address.advanced.js +89 -115
- package/dist.commonjs/address/advanced.d.ts +1 -1
- package/dist.commonjs/address/advanced.js +14 -30
- package/dist.commonjs/address/index.d.ts +44 -51
- package/dist.commonjs/address/index.js +65 -84
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +22 -47
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +14 -30
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.js +14 -30
- package/dist.commonjs/bytes/advanced.d.ts +2 -11
- package/dist.commonjs/bytes/index.d.ts +3 -9
- package/dist.commonjs/bytes/index.js +26 -28
- package/dist.commonjs/ckb/advanced.d.ts +1 -1
- package/dist.commonjs/ckb/advanced.js +22 -47
- package/dist.commonjs/ckb/index.d.ts +1 -1
- package/dist.commonjs/ckb/index.js +14 -30
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +260 -420
- package/dist.commonjs/ckb/molecule.advanced/generated.js +1332 -1536
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
- package/dist.commonjs/ckb/molecule.advanced/index.js +18 -34
- package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/script.advanced.js +9 -12
- package/dist.commonjs/ckb/script.d.ts +117 -121
- package/dist.commonjs/ckb/script.js +176 -220
- package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
- package/dist.commonjs/ckb/transaction.advanced.js +4 -4
- package/dist.commonjs/ckb/transaction.d.ts +722 -806
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +1190 -1424
- package/dist.commonjs/client/advanced.d.ts +1 -1
- package/dist.commonjs/client/advanced.js +14 -30
- package/dist.commonjs/client/client.advanced.d.ts +6 -23
- package/dist.commonjs/client/client.advanced.js +61 -89
- package/dist.commonjs/client/client.d.ts +54 -114
- package/dist.commonjs/client/client.js +182 -215
- package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -8
- package/dist.commonjs/client/clientPublicMainnet.advanced.js +189 -215
- package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -8
- package/dist.commonjs/client/clientPublicMainnet.js +15 -17
- package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +3 -6
- package/dist.commonjs/client/clientPublicTestnet.advanced.js +199 -227
- package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -8
- package/dist.commonjs/client/clientPublicTestnet.js +13 -13
- package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
- package/dist.commonjs/client/clientTypes.advanced.js +1 -1
- package/dist.commonjs/client/clientTypes.d.ts +26 -51
- package/dist.commonjs/client/clientTypes.js +22 -56
- package/dist.commonjs/client/index.d.ts +1 -1
- package/dist.commonjs/client/index.js +14 -30
- package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
- package/dist.commonjs/client/jsonRpc/advanced.js +14 -30
- package/dist.commonjs/client/jsonRpc/index.d.ts +75 -94
- package/dist.commonjs/client/jsonRpc/index.js +108 -135
- package/dist.commonjs/client/jsonRpc/transformers.d.ts +36 -76
- package/dist.commonjs/client/jsonRpc/transformers.js +152 -174
- package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
- package/dist.commonjs/fixedPoint/index.d.ts +3 -9
- package/dist.commonjs/fixedPoint/index.js +20 -26
- package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
- package/dist.commonjs/fixedPoint/index.test.js +36 -42
- package/dist.commonjs/hasher/advanced.d.ts +1 -1
- package/dist.commonjs/hasher/index.d.ts +37 -40
- package/dist.commonjs/hasher/index.js +48 -58
- package/dist.commonjs/hex/index.d.ts +1 -1
- package/dist.commonjs/hex/index.js +1 -1
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +22 -47
- package/dist.commonjs/num/index.d.ts +1 -1
- package/dist.commonjs/num/index.js +27 -39
- package/dist.commonjs/signer/btc/index.d.ts +1 -1
- package/dist.commonjs/signer/btc/index.js +14 -30
- package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
- package/dist.commonjs/signer/btc/signerBtc.js +66 -89
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
- package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
- package/dist.commonjs/signer/btc/verify.d.ts +2 -6
- package/dist.commonjs/signer/btc/verify.js +3 -10
- package/dist.commonjs/signer/ckb/index.d.ts +1 -1
- package/dist.commonjs/signer/ckb/index.js +14 -30
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts +5 -5
- package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +27 -41
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +11 -11
- package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +35 -45
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
- package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts +3 -9
- package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +5 -13
- package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +2 -6
- package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -11
- package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
- package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
- package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
- package/dist.commonjs/signer/dummy/dummy.js +16 -16
- package/dist.commonjs/signer/dummy/index.d.ts +1 -1
- package/dist.commonjs/signer/dummy/index.js +14 -30
- package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
- package/dist.commonjs/signer/dummy/openLink.js +7 -7
- package/dist.commonjs/signer/evm/index.d.ts +1 -1
- package/dist.commonjs/signer/evm/index.js +14 -30
- package/dist.commonjs/signer/evm/signerEvm.d.ts +38 -42
- package/dist.commonjs/signer/evm/signerEvm.js +70 -105
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
- package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
- package/dist.commonjs/signer/evm/verify.d.ts +2 -6
- package/dist.commonjs/signer/evm/verify.js +2 -7
- package/dist.commonjs/signer/index.d.ts +1 -1
- package/dist.commonjs/signer/index.js +14 -30
- package/dist.commonjs/signer/nostr/index.d.ts +1 -1
- package/dist.commonjs/signer/nostr/index.js +14 -30
- package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
- package/dist.commonjs/signer/nostr/signerNostr.js +71 -100
- package/dist.commonjs/signer/nostr/verify.d.ts +3 -9
- package/dist.commonjs/signer/nostr/verify.js +39 -50
- package/dist.commonjs/signer/signer/index.d.ts +162 -171
- package/dist.commonjs/signer/signer/index.js +198 -234
- package/dist.commonjs/utils/index.d.ts +9 -42
- package/dist.commonjs/utils/index.js +12 -18
- package/package.json +3 -3
|
@@ -1,33 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}
|
|
21
|
-
: function (o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
});
|
|
25
|
-
var __exportStar =
|
|
26
|
-
(this && this.__exportStar) ||
|
|
27
|
-
function (m, exports) {
|
|
28
|
-
for (var p in m)
|
|
29
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
30
|
-
__createBinding(exports, m, p);
|
|
31
|
-
};
|
|
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
|
+
};
|
|
32
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
17
|
__exportStar(require("./signerNostr"), exports);
|
|
@@ -4,63 +4,63 @@ import { Transaction, TransactionLike } from "../../ckb";
|
|
|
4
4
|
import { Hex } from "../../hex";
|
|
5
5
|
import { Signer, SignerSignType, SignerType } from "../signer";
|
|
6
6
|
export interface NostrEvent {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
id?: string;
|
|
8
|
+
pubkey?: string;
|
|
9
|
+
sig?: string;
|
|
10
|
+
created_at: number;
|
|
11
|
+
kind: number;
|
|
12
|
+
tags: string[][];
|
|
13
|
+
content: string;
|
|
14
14
|
}
|
|
15
15
|
export declare abstract class SignerNostr extends Signer {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
16
|
+
static CKB_SIG_HASH_ALL_TAG: string;
|
|
17
|
+
static CKB_UNLOCK_EVENT_KIND: number;
|
|
18
|
+
static CKB_UNLOCK_EVENT_CONTENT: string;
|
|
19
|
+
get type(): SignerType;
|
|
20
|
+
get signType(): SignerSignType;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the Nostr public key associated with the signer.
|
|
23
|
+
*
|
|
24
|
+
* @returns A promise that resolves to a string representing the Nostr public key.
|
|
25
|
+
*/
|
|
26
|
+
abstract getNostrPublicKey(): Promise<Hex>;
|
|
27
|
+
/**
|
|
28
|
+
* Sign a nostr event.
|
|
29
|
+
*
|
|
30
|
+
* @returns A promise that resolves to the signed event.
|
|
31
|
+
*/
|
|
32
|
+
abstract signNostrEvent(event: NostrEvent): Promise<Required<NostrEvent>>;
|
|
33
|
+
/**
|
|
34
|
+
* Sign a message.
|
|
35
|
+
*
|
|
36
|
+
* @returns A promise that resolves to the signature.
|
|
37
|
+
*/
|
|
38
|
+
signMessageRaw(message: string | BytesLike): Promise<Hex>;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the internal address, which is the EVM account in this case.
|
|
41
|
+
*
|
|
42
|
+
* @returns A promise that resolves to a string representing the internal address.
|
|
43
|
+
*/
|
|
44
|
+
getInternalAddress(): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
47
|
+
*
|
|
48
|
+
* @returns A promise that resolves to an array of Address objects.
|
|
49
|
+
*/
|
|
50
|
+
getAddressObjs(): Promise<Address[]>;
|
|
51
|
+
/**
|
|
52
|
+
* prepare a transaction before signing.
|
|
53
|
+
*
|
|
54
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
55
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
56
|
+
*/
|
|
57
|
+
prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
|
|
58
|
+
/**
|
|
59
|
+
* Signs a transaction without modifying it.
|
|
60
|
+
*
|
|
61
|
+
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
62
|
+
* @returns A promise that resolves to a signed Transaction object.
|
|
63
|
+
*/
|
|
64
|
+
signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
|
|
65
65
|
}
|
|
66
|
-
//# sourceMappingURL=signerNostr.d.ts.map
|
|
66
|
+
//# sourceMappingURL=signerNostr.d.ts.map
|
|
@@ -11,108 +11,79 @@ const hex_1 = require("../../hex");
|
|
|
11
11
|
const signer_1 = require("../signer");
|
|
12
12
|
const verify_1 = require("./verify");
|
|
13
13
|
class SignerNostr extends signer_1.Signer {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.client,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* Signs a transaction without modifying it.
|
|
85
|
-
*
|
|
86
|
-
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
87
|
-
* @returns A promise that resolves to a signed Transaction object.
|
|
88
|
-
*/
|
|
89
|
-
async signOnlyTransaction(txLike) {
|
|
90
|
-
let tx = ckb_1.Transaction.from(txLike);
|
|
91
|
-
const { script } = await this.getRecommendedAddressObj();
|
|
92
|
-
const info = await tx.getSignHashInfo(script, this.client);
|
|
93
|
-
if (!info) {
|
|
94
|
-
return tx;
|
|
14
|
+
get type() {
|
|
15
|
+
return signer_1.SignerType.Nostr;
|
|
16
|
+
}
|
|
17
|
+
get signType() {
|
|
18
|
+
return signer_1.SignerSignType.NostrEvent;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sign a message.
|
|
22
|
+
*
|
|
23
|
+
* @returns A promise that resolves to the signature.
|
|
24
|
+
*/
|
|
25
|
+
async signMessageRaw(message) {
|
|
26
|
+
return (0, hex_1.hexFrom)((await this.signNostrEvent((0, verify_1.buildNostrEventFromMessage)(message))).sig);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Gets the internal address, which is the EVM account in this case.
|
|
30
|
+
*
|
|
31
|
+
* @returns A promise that resolves to a string representing the internal address.
|
|
32
|
+
*/
|
|
33
|
+
async getInternalAddress() {
|
|
34
|
+
return bech32_1.bech32.encode("npub", bech32_1.bech32.toWords((0, bytes_1.bytesFrom)(await this.getNostrPublicKey())));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets an array of Address objects representing the known script addresses for the signer.
|
|
38
|
+
*
|
|
39
|
+
* @returns A promise that resolves to an array of Address objects.
|
|
40
|
+
*/
|
|
41
|
+
async getAddressObjs() {
|
|
42
|
+
const publicKey = await this.getNostrPublicKey();
|
|
43
|
+
return [
|
|
44
|
+
await address_1.Address.fromKnownScript(this.client, client_1.KnownScript.NostrLock, (0, hex_1.hexFrom)((0, bytes_1.bytesConcat)([0x00], (0, hasher_1.hashCkb)(publicKey).slice(0, 42)))),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* prepare a transaction before signing.
|
|
49
|
+
*
|
|
50
|
+
* @param txLike - The transaction to prepare, represented as a TransactionLike object.
|
|
51
|
+
* @returns A promise that resolves to the prepared Transaction object.
|
|
52
|
+
*/
|
|
53
|
+
async prepareTransaction(txLike) {
|
|
54
|
+
const tx = ckb_1.Transaction.from(txLike);
|
|
55
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
56
|
+
await tx.addCellDepsOfKnownScripts(this.client, client_1.KnownScript.NostrLock);
|
|
57
|
+
await tx.prepareSighashAllWitness(script, 572, this.client);
|
|
58
|
+
return tx;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Signs a transaction without modifying it.
|
|
62
|
+
*
|
|
63
|
+
* @param txLike - The transaction to sign, represented as a TransactionLike object.
|
|
64
|
+
* @returns A promise that resolves to a signed Transaction object.
|
|
65
|
+
*/
|
|
66
|
+
async signOnlyTransaction(txLike) {
|
|
67
|
+
let tx = ckb_1.Transaction.from(txLike);
|
|
68
|
+
const { script } = await this.getRecommendedAddressObj();
|
|
69
|
+
const info = await tx.getSignHashInfo(script, this.client);
|
|
70
|
+
if (!info) {
|
|
71
|
+
return tx;
|
|
72
|
+
}
|
|
73
|
+
const signedEvent = (0, bytes_1.bytesFrom)(JSON.stringify(await this.signNostrEvent({
|
|
74
|
+
pubkey: (await this.getNostrPublicKey()).slice(2),
|
|
75
|
+
tags: [[SignerNostr.CKB_SIG_HASH_ALL_TAG, info.message.slice(2)]],
|
|
76
|
+
created_at: Math.floor(Date.now() / 1000),
|
|
77
|
+
kind: SignerNostr.CKB_UNLOCK_EVENT_KIND,
|
|
78
|
+
content: SignerNostr.CKB_UNLOCK_EVENT_CONTENT,
|
|
79
|
+
})), "utf8");
|
|
80
|
+
const witness = ckb_1.WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
81
|
+
witness.lock = (0, hex_1.hexFrom)(signedEvent);
|
|
82
|
+
tx.setWitnessArgsAt(info.position, witness);
|
|
83
|
+
return tx;
|
|
95
84
|
}
|
|
96
|
-
const signedEvent = (0, bytes_1.bytesFrom)(
|
|
97
|
-
JSON.stringify(
|
|
98
|
-
await this.signNostrEvent({
|
|
99
|
-
pubkey: (await this.getNostrPublicKey()).slice(2),
|
|
100
|
-
tags: [[SignerNostr.CKB_SIG_HASH_ALL_TAG, info.message.slice(2)]],
|
|
101
|
-
created_at: Math.floor(Date.now() / 1000),
|
|
102
|
-
kind: SignerNostr.CKB_UNLOCK_EVENT_KIND,
|
|
103
|
-
content: SignerNostr.CKB_UNLOCK_EVENT_CONTENT,
|
|
104
|
-
}),
|
|
105
|
-
),
|
|
106
|
-
"utf8",
|
|
107
|
-
);
|
|
108
|
-
const witness = ckb_1.WitnessArgs.fromBytes(tx.witnesses[info.position]);
|
|
109
|
-
witness.lock = (0, hex_1.hexFrom)(signedEvent);
|
|
110
|
-
tx.setWitnessArgsAt(info.position, witness);
|
|
111
|
-
return tx;
|
|
112
|
-
}
|
|
113
85
|
}
|
|
114
86
|
exports.SignerNostr = SignerNostr;
|
|
115
87
|
SignerNostr.CKB_SIG_HASH_ALL_TAG = "ckb_sighash_all";
|
|
116
88
|
SignerNostr.CKB_UNLOCK_EVENT_KIND = 23334;
|
|
117
|
-
SignerNostr.CKB_UNLOCK_EVENT_CONTENT =
|
|
118
|
-
"Signing a CKB transaction\n\nIMPORTANT: Please verify the integrity and authenticity of connected Nostr client before signing this message\n";
|
|
89
|
+
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,11 +1,5 @@
|
|
|
1
1
|
import { BytesLike } from "../../bytes";
|
|
2
2
|
import { NostrEvent } from "./signerNostr";
|
|
3
|
-
export declare function buildNostrEventFromMessage(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function verifyMessageNostrEvent(
|
|
7
|
-
message: string | BytesLike,
|
|
8
|
-
signature: string,
|
|
9
|
-
address: string,
|
|
10
|
-
): boolean;
|
|
11
|
-
//# sourceMappingURL=verify.d.ts.map
|
|
3
|
+
export declare function buildNostrEventFromMessage(message: string | BytesLike): NostrEvent;
|
|
4
|
+
export declare function verifyMessageNostrEvent(message: string | BytesLike, signature: string, address: string): boolean;
|
|
5
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -7,58 +7,47 @@ const bech32_1 = require("bech32");
|
|
|
7
7
|
const bytes_1 = require("../../bytes");
|
|
8
8
|
const hex_1 = require("../../hex");
|
|
9
9
|
function buildNostrEventFromMessage(message) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
content:
|
|
32
|
-
typeof message === "string" ? message : (0, hex_1.hexFrom)(message),
|
|
33
|
-
tags: [],
|
|
34
|
-
};
|
|
10
|
+
if (typeof message === "string") {
|
|
11
|
+
try {
|
|
12
|
+
const event = JSON.parse(message);
|
|
13
|
+
if (typeof event === "object" &&
|
|
14
|
+
typeof event.created_at === "number" &&
|
|
15
|
+
typeof event.kind === "number" &&
|
|
16
|
+
typeof event.content === "string" &&
|
|
17
|
+
Array.isArray(event.args) &&
|
|
18
|
+
event.args.every((tag) => Array.isArray(tag) &&
|
|
19
|
+
tag.every((v) => typeof v === "string"))) {
|
|
20
|
+
return event;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (_) { }
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
kind: 23335,
|
|
27
|
+
created_at: 0,
|
|
28
|
+
content: typeof message === "string" ? message : (0, hex_1.hexFrom)(message),
|
|
29
|
+
tags: [],
|
|
30
|
+
};
|
|
35
31
|
}
|
|
36
32
|
exports.buildNostrEventFromMessage = buildNostrEventFromMessage;
|
|
37
33
|
function verifyMessageNostrEvent(message, signature, address) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
signature.slice(2),
|
|
57
|
-
eventHash.slice(2),
|
|
58
|
-
publicKey,
|
|
59
|
-
);
|
|
60
|
-
} catch (_) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
34
|
+
const { words } = bech32_1.bech32.decode(address);
|
|
35
|
+
const publicKey = (0, hex_1.hexFrom)(bech32_1.bech32.fromWords(words)).slice(2);
|
|
36
|
+
const event = buildNostrEventFromMessage(message);
|
|
37
|
+
const serialized = JSON.stringify([
|
|
38
|
+
0,
|
|
39
|
+
publicKey,
|
|
40
|
+
event.created_at,
|
|
41
|
+
event.kind,
|
|
42
|
+
event.tags,
|
|
43
|
+
event.content,
|
|
44
|
+
]);
|
|
45
|
+
const eventHash = (0, hex_1.hexFrom)((0, sha256_1.sha256)((0, bytes_1.bytesFrom)(serialized, "utf8")));
|
|
46
|
+
try {
|
|
47
|
+
return secp256k1_1.schnorr.verify(signature.slice(2), eventHash.slice(2), publicKey);
|
|
48
|
+
}
|
|
49
|
+
catch (_) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
63
52
|
}
|
|
64
53
|
exports.verifyMessageNostrEvent = verifyMessageNostrEvent;
|