Commit f14c77f 1 parent a8b7f41 commit f14c77f Copy full SHA for f14c77f
File tree 4 files changed +36
-2
lines changed
4 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ export * from './src/address/index';
2
2
export * from './src/provider' ;
3
3
export * from './src/call' ;
4
4
export * from './src/transactions/signTransaction' ;
5
+ export * from './src/signatures' ;
Original file line number Diff line number Diff line change @@ -2,14 +2,15 @@ import { SignTransactionResponse } from '../transactions/signTransaction';
2
2
import { GetAddressResponse } from '../address' ;
3
3
4
4
export interface BitcoinNetwork {
5
- type : string ;
6
- address : string ;
5
+ type : 'Mainnet' | 'Testnet' ;
6
+ address ? : string ;
7
7
}
8
8
9
9
export interface BitcoinProvider {
10
10
connect : ( request : string ) => Promise < GetAddressResponse > ;
11
11
call : ( request : string ) => Promise < Record < string , any > > ;
12
12
signTransaction : ( request : string ) => Promise < SignTransactionResponse > ;
13
+ signMessage : ( request : string ) => Promise < string >
13
14
}
14
15
15
16
declare global {
Original file line number Diff line number Diff line change
1
+ import { createUnsecuredToken , Json } from 'jsontokens' ;
2
+ import { SignMessageOptions } from './types' ;
3
+
4
+ export const signMessage = async ( options : SignMessageOptions ) => {
5
+ const provider = window . BitcoinProvider ;
6
+ if ( ! provider ) {
7
+ throw new Error ( 'No Bitcoin Wallet installed' ) ;
8
+ }
9
+ try {
10
+ const request = createUnsecuredToken ( options . payload as unknown as Json ) ;
11
+ const response = await provider . signMessage ( request ) ;
12
+ options . onFinish ?.( response ) ;
13
+ } catch ( error ) {
14
+ console . error ( '[Connect] Error during Signing request' , error ) ;
15
+ options . onCancel ?.( ) ;
16
+ }
17
+ } ;
18
+
19
+ export * from './types' ;
Original file line number Diff line number Diff line change
1
+ import { BitcoinNetwork } from '../provider' ;
2
+
3
+ export interface SignMessagePayload {
4
+ address : string ;
5
+ message : string ;
6
+ network : BitcoinNetwork ;
7
+ }
8
+
9
+ export interface SignMessageOptions {
10
+ onFinish : ( response : string ) => void ;
11
+ onCancel : ( ) => void ;
12
+ payload : SignMessagePayload ;
13
+ }
You can’t perform that action at this time.
0 commit comments