@ckb-ccc/core 1.11.4 → 1.11.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/CHANGELOG.md +14 -0
- package/dist/molecule/entity.d.ts +3 -3
- package/dist/molecule/entity.d.ts.map +1 -1
- package/dist/molecule/entity.js +1 -1
- package/dist/signer/nostr/verify.js +4 -4
- package/dist.commonjs/molecule/entity.d.ts +3 -3
- package/dist.commonjs/molecule/entity.d.ts.map +1 -1
- package/dist.commonjs/molecule/entity.js +1 -1
- package/dist.commonjs/signer/nostr/verify.js +5 -5
- package/package.json +1 -1
- package/src/molecule/entity.ts +10 -9
- package/src/signer/nostr/verify.ts +4 -4
- /package/{vitest.config.ts → vitest.config.mts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ckb-ccc/core
|
|
2
2
|
|
|
3
|
+
## 1.11.5
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#306](https://github.com/ckb-devrel/ccc/pull/306) [`cec9b39`](https://github.com/ckb-devrel/ccc/commit/cec9b39345fc37a6ae72c0774059b2e31efc9e89) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix(core): nostr signature verification
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
- [#304](https://github.com/ckb-devrel/ccc/pull/304) [`c95913f`](https://github.com/ckb-devrel/ccc/commit/c95913f58c889c9d8c0b164014f9917501c11dbc) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix(core): `ccc.mol.codec` decorator
|
|
13
|
+
|
|
14
|
+
* The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.
|
|
15
|
+
* Decorator function return type '...' is not assignable to type '...'
|
|
16
|
+
|
|
3
17
|
## 1.11.4
|
|
4
18
|
### Patch Changes
|
|
5
19
|
|
|
@@ -102,11 +102,11 @@ export declare abstract class Entity {
|
|
|
102
102
|
* }
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
|
-
export declare function codec<Encodable, TypeLike extends Encodable, Decoded extends TypeLike, Type extends
|
|
105
|
+
export declare function codec<Encodable, TypeLike extends Encodable, Decoded extends TypeLike>(codec: Codec<Encodable, Decoded>): <Type extends TypeLike, ConstructorType extends Constructor<Type> & {
|
|
106
106
|
from(decoded: TypeLike): Type;
|
|
107
107
|
byteLength?: number;
|
|
108
108
|
encode(encodable: TypeLike): Bytes;
|
|
109
|
-
decode(bytesLike: BytesLike):
|
|
109
|
+
decode(bytesLike: BytesLike): Type;
|
|
110
110
|
fromBytes(bytes: BytesLike): Type;
|
|
111
|
-
}>(
|
|
111
|
+
}>(Constructor: ConstructorType, ..._: unknown[]) => ConstructorType;
|
|
112
112
|
//# sourceMappingURL=entity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/molecule/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAW,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;GAGG;AACH,8BAAsB,MAAM;IAC1B;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,WAAW;QA6D1C;;;;WAIG;mBACQ,KAAK;QAMhB;;;;WAIG;iBACM,OAAO;QAMhB;;;;;WAKG;kBACO,WAAW,GAAG,OAAO;QAe/B;;;;WAIG;gBACK,GAAG;;QA3GX;;;;WAIG;qBACiB,MAAM;QAC1B;;;;;;;WAOG;kBACc,WAAW,GAAG,KAAK;QAKpC;;;;;;;WAOG;kBACc,SAAS,GAAG,OAAO;QAMpC;;;;;;;WAOG;0BACsB,SAAS,GAAG,OA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AAS,EAC1B,OAAO,SAAS,QAAQ,EACxB,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,IAE9B,IAAI,SAAS,QAAQ,EACrB,eAAe,SAAS,WAAW,CAAC,IAAI,CAAC,GAAG;IAC1C,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,SAAS,EAAE,QAAQ,GAAG,KAAK,CAAC;IACnC,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACnC,EACD,aAAa,eAAe,EAAE,GAAG,GAAG,OAAO,EAAE,qBAchD"}
|
package/dist/molecule/entity.js
CHANGED
|
@@ -115,7 +115,7 @@ export class Entity {
|
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
|
117
117
|
export function codec(codec) {
|
|
118
|
-
return function (Constructor) {
|
|
118
|
+
return function (Constructor, ..._) {
|
|
119
119
|
Constructor.byteLength = codec.byteLength;
|
|
120
120
|
Constructor.encode = function (encodable) {
|
|
121
121
|
return codec.encode(encodable);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { schnorr } from "@noble/curves/secp256k1";
|
|
2
|
-
import { sha256 } from "@noble/hashes/
|
|
2
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
3
3
|
import { bech32 } from "bech32";
|
|
4
4
|
import { bytesFrom } from "../../bytes/index.js";
|
|
5
5
|
import { hexFrom } from "../../hex/index.js";
|
|
@@ -43,11 +43,11 @@ export function nostrEventHash(event) {
|
|
|
43
43
|
}
|
|
44
44
|
export function verifyMessageNostrEvent(message, signature, address) {
|
|
45
45
|
const { words } = bech32.decode(address);
|
|
46
|
-
const
|
|
46
|
+
const pubkey = hexFrom(bech32.fromWords(words)).slice(2);
|
|
47
47
|
const event = buildNostrEventFromMessage(message);
|
|
48
|
-
const eventHash = nostrEventHash(event);
|
|
48
|
+
const eventHash = nostrEventHash({ ...event, pubkey });
|
|
49
49
|
try {
|
|
50
|
-
return schnorr.verify(hexFrom(signature).slice(2), eventHash,
|
|
50
|
+
return schnorr.verify(hexFrom(signature).slice(2), eventHash, pubkey);
|
|
51
51
|
}
|
|
52
52
|
catch (_) {
|
|
53
53
|
return false;
|
|
@@ -102,11 +102,11 @@ export declare abstract class Entity {
|
|
|
102
102
|
* }
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
|
-
export declare function codec<Encodable, TypeLike extends Encodable, Decoded extends TypeLike, Type extends
|
|
105
|
+
export declare function codec<Encodable, TypeLike extends Encodable, Decoded extends TypeLike>(codec: Codec<Encodable, Decoded>): <Type extends TypeLike, ConstructorType extends Constructor<Type> & {
|
|
106
106
|
from(decoded: TypeLike): Type;
|
|
107
107
|
byteLength?: number;
|
|
108
108
|
encode(encodable: TypeLike): Bytes;
|
|
109
|
-
decode(bytesLike: BytesLike):
|
|
109
|
+
decode(bytesLike: BytesLike): Type;
|
|
110
110
|
fromBytes(bytes: BytesLike): Type;
|
|
111
|
-
}>(
|
|
111
|
+
}>(Constructor: ConstructorType, ..._: unknown[]) => ConstructorType;
|
|
112
112
|
//# sourceMappingURL=entity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/molecule/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAW,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;GAGG;AACH,8BAAsB,MAAM;IAC1B;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,WAAW;QA6D1C;;;;WAIG;mBAC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G;0BACsB,SAAS,GAAG,OAAO;QAM5C;;;;;;;WAOG;gBACY,WAAW,GAAG,OAAO;;IA4DxC,QAAQ,CAAC,OAAO,IAAI,KAAK;IACzB,QAAQ,CAAC,IAAI,IAAI,GAAG;IACpB,QAAQ,CAAC,KAAK,IAAI,MAAM;CACzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CACnB,SAAS,EACT,QAAQ,SAAS,SAAS,EAC1B,OAAO,SAAS,QAAQ,EACxB,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,IAE9B,IAAI,SAAS,QAAQ,EACrB,eAAe,SAAS,WAAW,CAAC,IAAI,CAAC,GAAG;IAC1C,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,SAAS,EAAE,QAAQ,GAAG,KAAK,CAAC;IACnC,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACnC,EACD,aAAa,eAAe,EAAE,GAAG,GAAG,OAAO,EAAE,qBAchD"}
|
|
@@ -120,7 +120,7 @@ exports.Entity = Entity;
|
|
|
120
120
|
* ```
|
|
121
121
|
*/
|
|
122
122
|
function codec(codec) {
|
|
123
|
-
return function (Constructor) {
|
|
123
|
+
return function (Constructor, ..._) {
|
|
124
124
|
Constructor.byteLength = codec.byteLength;
|
|
125
125
|
Constructor.encode = function (encodable) {
|
|
126
126
|
return codec.encode(encodable);
|
|
@@ -4,7 +4,7 @@ exports.buildNostrEventFromMessage = buildNostrEventFromMessage;
|
|
|
4
4
|
exports.nostrEventHash = nostrEventHash;
|
|
5
5
|
exports.verifyMessageNostrEvent = verifyMessageNostrEvent;
|
|
6
6
|
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
7
|
-
const
|
|
7
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
8
8
|
const bech32_1 = require("bech32");
|
|
9
9
|
const index_js_1 = require("../../bytes/index.js");
|
|
10
10
|
const index_js_2 = require("../../hex/index.js");
|
|
@@ -44,15 +44,15 @@ function nostrEventHash(event) {
|
|
|
44
44
|
event.tags,
|
|
45
45
|
event.content,
|
|
46
46
|
]);
|
|
47
|
-
return (0,
|
|
47
|
+
return (0, sha2_js_1.sha256)((0, index_js_1.bytesFrom)(serialized, "utf8"));
|
|
48
48
|
}
|
|
49
49
|
function verifyMessageNostrEvent(message, signature, address) {
|
|
50
50
|
const { words } = bech32_1.bech32.decode(address);
|
|
51
|
-
const
|
|
51
|
+
const pubkey = (0, index_js_2.hexFrom)(bech32_1.bech32.fromWords(words)).slice(2);
|
|
52
52
|
const event = buildNostrEventFromMessage(message);
|
|
53
|
-
const eventHash = nostrEventHash(event);
|
|
53
|
+
const eventHash = nostrEventHash({ ...event, pubkey });
|
|
54
54
|
try {
|
|
55
|
-
return secp256k1_1.schnorr.verify((0, index_js_2.hexFrom)(signature).slice(2), eventHash,
|
|
55
|
+
return secp256k1_1.schnorr.verify((0, index_js_2.hexFrom)(signature).slice(2), eventHash, pubkey);
|
|
56
56
|
}
|
|
57
57
|
catch (_) {
|
|
58
58
|
return false;
|
package/package.json
CHANGED
package/src/molecule/entity.ts
CHANGED
|
@@ -156,16 +156,17 @@ export function codec<
|
|
|
156
156
|
Encodable,
|
|
157
157
|
TypeLike extends Encodable,
|
|
158
158
|
Decoded extends TypeLike,
|
|
159
|
-
Type extends object & TypeLike,
|
|
160
|
-
ConstructorType extends Constructor<Type> & {
|
|
161
|
-
from(decoded: TypeLike): Type;
|
|
162
|
-
byteLength?: number;
|
|
163
|
-
encode(encodable: TypeLike): Bytes;
|
|
164
|
-
decode(bytesLike: BytesLike): TypeLike;
|
|
165
|
-
fromBytes(bytes: BytesLike): Type;
|
|
166
|
-
},
|
|
167
159
|
>(codec: Codec<Encodable, Decoded>) {
|
|
168
|
-
return function
|
|
160
|
+
return function <
|
|
161
|
+
Type extends TypeLike,
|
|
162
|
+
ConstructorType extends Constructor<Type> & {
|
|
163
|
+
from(decoded: TypeLike): Type;
|
|
164
|
+
byteLength?: number;
|
|
165
|
+
encode(encodable: TypeLike): Bytes;
|
|
166
|
+
decode(bytesLike: BytesLike): Type;
|
|
167
|
+
fromBytes(bytes: BytesLike): Type;
|
|
168
|
+
},
|
|
169
|
+
>(Constructor: ConstructorType, ..._: unknown[]) {
|
|
169
170
|
Constructor.byteLength = codec.byteLength;
|
|
170
171
|
Constructor.encode = function (encodable: TypeLike) {
|
|
171
172
|
return codec.encode(encodable);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { schnorr } from "@noble/curves/secp256k1";
|
|
2
|
-
import { sha256 } from "@noble/hashes/
|
|
2
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
3
3
|
import { bech32 } from "bech32";
|
|
4
4
|
import { Bytes, BytesLike, bytesFrom } from "../../bytes/index.js";
|
|
5
5
|
import { hexFrom } from "../../hex/index.js";
|
|
@@ -59,13 +59,13 @@ export function verifyMessageNostrEvent(
|
|
|
59
59
|
address: string,
|
|
60
60
|
): boolean {
|
|
61
61
|
const { words } = bech32.decode(address);
|
|
62
|
-
const
|
|
62
|
+
const pubkey = hexFrom(bech32.fromWords(words)).slice(2);
|
|
63
63
|
|
|
64
64
|
const event = buildNostrEventFromMessage(message);
|
|
65
|
-
const eventHash = nostrEventHash(event);
|
|
65
|
+
const eventHash = nostrEventHash({ ...event, pubkey });
|
|
66
66
|
|
|
67
67
|
try {
|
|
68
|
-
return schnorr.verify(hexFrom(signature).slice(2), eventHash,
|
|
68
|
+
return schnorr.verify(hexFrom(signature).slice(2), eventHash, pubkey);
|
|
69
69
|
} catch (_) {
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
File without changes
|