File tree Expand file tree Collapse file tree 5 files changed +45
-15
lines changed
packages/core/src/signer/nostr Expand file tree Collapse file tree 5 files changed +45
-15
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @ckb-ccc/core " : minor
3
+ ---
4
+
5
+ feat(core): SignerNostrPublicKeyReadonly
Original file line number Diff line number Diff line change 1
1
export * from "./signerNostr.js" ;
2
2
export * from "./signerNostrPrivateKey.js" ;
3
+ export * from "./signerNostrPublicKeyReadonly.js" ;
3
4
export * from "./verify.js" ;
Original file line number Diff line number Diff line change @@ -50,7 +50,9 @@ export abstract class SignerNostr extends Signer {
50
50
*
51
51
* @returns A promise that resolves to the signed event.
52
52
*/
53
- abstract signNostrEvent ( event : NostrEvent ) : Promise < Required < NostrEvent > > ;
53
+ async signNostrEvent ( _event : NostrEvent ) : Promise < Required < NostrEvent > > {
54
+ throw Error ( "SignerNostr.signNostrEvent not implemented" ) ;
55
+ }
54
56
55
57
/**
56
58
* Sign a message.
Original file line number Diff line number Diff line change 1
1
import { schnorr } from "@noble/curves/secp256k1" ;
2
2
import { Client } from "../../client/index.js" ;
3
3
import { Hex , hexFrom , HexLike } from "../../hex/index.js" ;
4
- import { NostrEvent , SignerNostr } from "./signerNostr.js" ;
4
+ import { NostrEvent } from "./signerNostr.js" ;
5
+ import { SignerNostrPublicKeyReadonly } from "./signerNostrPublicKeyReadonly.js" ;
5
6
import { nostrEventHash } from "./verify.js" ;
6
7
7
- export class SignerNostrPrivateKey extends SignerNostr {
8
+ export class SignerNostrPrivateKey extends SignerNostrPublicKeyReadonly {
8
9
private readonly privateKey : Hex ;
9
10
10
- constructor ( client : Client , privateKey : HexLike ) {
11
- super ( client ) ;
12
- this . privateKey = hexFrom ( privateKey ) ;
13
- }
14
-
15
- async connect ( ) : Promise < void > { }
16
-
17
- async isConnected ( ) : Promise < boolean > {
18
- return true ;
19
- }
11
+ constructor ( client : Client , privateKeyLike : HexLike ) {
12
+ const privateKey = hexFrom ( privateKeyLike ) ;
13
+ super ( client , schnorr . getPublicKey ( privateKey . slice ( 2 ) ) ) ;
20
14
21
- async getNostrPublicKey ( ) : Promise < Hex > {
22
- return hexFrom ( schnorr . getPublicKey ( this . privateKey . slice ( 2 ) ) ) ;
15
+ this . privateKey = privateKey ;
23
16
}
24
17
25
18
async signNostrEvent ( event : NostrEvent ) : Promise < Required < NostrEvent > > {
Original file line number Diff line number Diff line change
1
+ import { bech32 } from "bech32" ;
2
+ import { Client } from "../../client/index.js" ;
3
+ import { Hex , hexFrom , HexLike } from "../../hex/index.js" ;
4
+ import { SignerNostr } from "./signerNostr.js" ;
5
+
6
+ export class SignerNostrPublicKeyReadonly extends SignerNostr {
7
+ public readonly publicKey : Hex ;
8
+
9
+ constructor ( client : Client , publicKey : HexLike ) {
10
+ super ( client ) ;
11
+
12
+ if ( typeof publicKey === "string" && publicKey . startsWith ( "npub" ) ) {
13
+ const { words } = bech32 . decode ( publicKey ) ;
14
+ this . publicKey = hexFrom ( bech32 . fromWords ( words ) ) ;
15
+ } else {
16
+ this . publicKey = hexFrom ( publicKey ) ;
17
+ }
18
+ }
19
+
20
+ async connect ( ) : Promise < void > { }
21
+
22
+ async isConnected ( ) : Promise < boolean > {
23
+ return true ;
24
+ }
25
+
26
+ async getNostrPublicKey ( ) : Promise < Hex > {
27
+ return this . publicKey ;
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments