@@ -5,8 +5,9 @@ import { z } from "zod";
5
5
6
6
import { handleAggregateSignatureShares } from "./multisig/handleAggregateSignatureShares" ;
7
7
import { handleCreateSigningPackage } from "./multisig/handleCreateSigningPackage" ;
8
- import { ledgerDkg } from "./utils/dkg " ;
8
+ import { mapLedgerError } from "./utils/ledger " ;
9
9
import { ledgerManager , ConnectionStatus } from "./utils/ledgerManager" ;
10
+ import { ledgerMultiSigner } from "./utils/ledgerMultiSigner" ;
10
11
import { handleSendTransactionInput } from "../transactions/handleSendTransaction" ;
11
12
import { t } from "../trpc" ;
12
13
@@ -44,33 +45,43 @@ export const ledgerRouter = t.router({
44
45
return ledgerManager . markAccountAsLedger ( opts . input . publicAddress ) ;
45
46
} ) ,
46
47
createSigningCommitment : t . procedure
47
- . input ( z . object ( { txHash : z . string ( ) , identities : z . array ( z . string ( ) ) } ) )
48
+ . input (
49
+ z . object ( {
50
+ unsignedTransaction : z . string ( ) ,
51
+ identities : z . array ( z . string ( ) ) ,
52
+ } ) ,
53
+ )
48
54
. mutation ( async ( opts ) => {
49
- const rawCommitments = await ledgerDkg . dkgGetCommitments (
50
- opts . input . txHash ,
55
+ const transaction = new UnsignedTransaction (
56
+ Buffer . from ( opts . input . unsignedTransaction , "hex" ) ,
51
57
) ;
58
+ const rawCommitments = await ledgerMultiSigner
59
+ . dkgGetCommitments ( transaction )
60
+ . catch ( ( e ) => mapLedgerError ( e , ledgerMultiSigner ) ) ;
52
61
53
62
const signingCommitment = multisig . SigningCommitment . fromRaw (
54
63
opts . input . identities [ 0 ] ,
55
64
rawCommitments ,
56
- Buffer . from ( opts . input . txHash , "hex" ) ,
65
+ transaction . hash ( ) ,
57
66
opts . input . identities ,
58
67
) ;
59
68
60
69
return signingCommitment . serialize ( ) . toString ( "hex" ) ;
61
70
} ) ,
62
71
getLedgerIdentity : t . procedure . input ( z . undefined ( ) ) . mutation ( async ( ) => {
63
- const identity = await ledgerDkg . dkgGetIdentity ( 0 ) ;
72
+ const identity = await ledgerMultiSigner
73
+ . dkgGetIdentity ( 0 )
74
+ . catch ( ( e ) => mapLedgerError ( e , ledgerMultiSigner ) ) ;
75
+
64
76
return identity . toString ( "hex" ) ;
65
77
} ) ,
66
78
reviewTransaction : t . procedure
67
79
. input ( z . object ( { unsignedTransaction : z . string ( ) } ) )
68
80
. mutation ( async ( opts ) => {
69
- console . log ( "reviewTransaction" ) ;
70
- const result = await ledgerDkg . reviewTransaction (
71
- opts . input . unsignedTransaction ,
72
- ) ;
73
- console . log ( "reviewTransactionComplete" ) ;
81
+ const result = await ledgerMultiSigner
82
+ . reviewTransaction ( opts . input . unsignedTransaction )
83
+ . catch ( ( e ) => mapLedgerError ( e , ledgerMultiSigner ) ) ;
84
+
74
85
return result . toString ( "hex" ) ;
75
86
} ) ,
76
87
createSignatureShare : t . procedure
@@ -85,22 +96,16 @@ export const ledgerRouter = t.router({
85
96
const unsignedTransaction = new UnsignedTransaction (
86
97
Buffer . from ( opts . input . unsignedTransaction , "hex" ) ,
87
98
) ;
88
- const ref = unsignedTransaction . takeReference ( ) ;
89
- const publicKeyRandomness = ref . publicKeyRandomness ( ) ;
90
- const hash = ref . hash ( ) ;
91
- unsignedTransaction . returnReference ( ) ;
92
99
93
100
const frostSigningPackage = new multisig . SigningPackage (
94
101
Buffer . from ( opts . input . signingPackage , "hex" ) ,
95
102
)
96
103
. frostSigningPackage ( )
97
104
. toString ( "hex" ) ;
98
105
99
- const frostSignatureShare = await ledgerDkg . dkgSign (
100
- publicKeyRandomness ,
101
- frostSigningPackage ,
102
- hash . toString ( "hex" ) ,
103
- ) ;
106
+ const frostSignatureShare = await ledgerMultiSigner
107
+ . dkgSign ( unsignedTransaction , frostSigningPackage )
108
+ . catch ( ( e ) => mapLedgerError ( e , ledgerMultiSigner ) ) ;
104
109
105
110
return multisig . SignatureShare . fromFrost (
106
111
frostSignatureShare ,
0 commit comments