5
5
Cbor ,
6
6
Cip30DataSignature ,
7
7
Cip95WalletApi ,
8
+ DAppConnectorContext ,
8
9
DataSignError ,
9
10
DataSignErrorCode ,
10
11
Paginate ,
@@ -13,7 +14,8 @@ import {
13
14
TxSignError ,
14
15
TxSignErrorCode ,
15
16
WalletApi ,
16
- WalletApiExtension
17
+ WalletApiExtension ,
18
+ WithDAppConnectorContext
17
19
} from '@cardano-sdk/dapp-connector' ;
18
20
import { Cardano , Serialization , TxCBOR , coalesceValueQuantities } from '@cardano-sdk/core' ;
19
21
import { HexBlob , ManagedFreeableScope } from '@cardano-sdk/util' ;
@@ -36,13 +38,15 @@ export enum Cip30ConfirmationCallbackType {
36
38
37
39
export type SignDataCallbackParams = {
38
40
type : Cip30ConfirmationCallbackType . SignData ;
41
+ context : DAppConnectorContext ;
39
42
data : {
40
43
addr : Cardano . PaymentAddress | Cardano . DRepID ;
41
44
payload : HexBlob ;
42
45
} ;
43
46
} ;
44
47
45
48
export type SignTxCallbackParams = {
49
+ context : DAppConnectorContext ;
46
50
type : Cip30ConfirmationCallbackType . SignTx ;
47
51
data : Cardano . Tx ;
48
52
} ;
@@ -279,9 +283,10 @@ const baseCip30WalletApi = (
279
283
}
280
284
} ,
281
285
// eslint-disable-next-line max-statements, sonarjs/cognitive-complexity,complexity
282
- getCollateral : async ( {
283
- amount = new Serialization . Value ( MAX_COLLATERAL_AMOUNT ) . toCbor ( )
284
- } : { amount ?: Cbor } = { } ) : Promise <
286
+ getCollateral : async (
287
+ _ : DAppConnectorContext ,
288
+ { amount = new Serialization . Value ( MAX_COLLATERAL_AMOUNT ) . toCbor ( ) } : { amount ?: Cbor } = { }
289
+ ) : Promise <
285
290
Cbor [ ] | null
286
291
// eslint-disable-next-line sonarjs/cognitive-complexity, max-statements
287
292
> => {
@@ -371,7 +376,7 @@ const baseCip30WalletApi = (
371
376
logger . debug ( 'getting unused addresses' ) ;
372
377
return Promise . resolve ( [ ] ) ;
373
378
} ,
374
- getUsedAddresses : async ( _paginate ?: Paginate ) : Promise < Cbor [ ] > => {
379
+ getUsedAddresses : async ( ) : Promise < Cbor [ ] > => {
375
380
logger . debug ( 'getting used addresses' ) ;
376
381
377
382
const wallet = await firstValueFrom ( wallet$ ) ;
@@ -383,7 +388,7 @@ const baseCip30WalletApi = (
383
388
return addresses . map ( ( groupAddresses ) => cardanoAddressToCbor ( groupAddresses . address ) ) ;
384
389
}
385
390
} ,
386
- getUtxos : async ( amount ?: Cbor , paginate ?: Paginate ) : Promise < Cbor [ ] | null > => {
391
+ getUtxos : async ( _ : DAppConnectorContext , amount ?: Cbor , paginate ?: Paginate ) : Promise < Cbor [ ] | null > => {
387
392
const scope = new ManagedFreeableScope ( ) ;
388
393
try {
389
394
const wallet = await firstValueFrom ( wallet$ ) ;
@@ -402,6 +407,7 @@ const baseCip30WalletApi = (
402
407
}
403
408
} ,
404
409
signData : async (
410
+ context : DAppConnectorContext ,
405
411
addr : Cardano . PaymentAddress | Cardano . DRepID | Bytes ,
406
412
payload : Bytes
407
413
) : Promise < Cip30DataSignature > => {
@@ -411,6 +417,7 @@ const baseCip30WalletApi = (
411
417
412
418
const shouldProceed = await confirmationCallback
413
419
. signData ( {
420
+ context,
414
421
data : {
415
422
addr : signWith ,
416
423
payload : hexBlobPayload
@@ -422,14 +429,15 @@ const baseCip30WalletApi = (
422
429
if ( shouldProceed ) {
423
430
const wallet = await firstValueFrom ( wallet$ ) ;
424
431
return wallet . signData ( {
432
+ origin : context . origin ,
425
433
payload : hexBlobPayload ,
426
434
signWith
427
435
} ) ;
428
436
}
429
437
logger . debug ( 'sign data declined' ) ;
430
438
throw new DataSignError ( DataSignErrorCode . UserDeclined , 'user declined signing' ) ;
431
439
} ,
432
- signTx : async ( tx : Cbor , partialSign ?: Boolean ) : Promise < Cbor > => {
440
+ signTx : async ( context : DAppConnectorContext , tx : Cbor , partialSign ?: Boolean ) : Promise < Cbor > => {
433
441
const scope = new ManagedFreeableScope ( ) ;
434
442
logger . debug ( 'signTx' ) ;
435
443
const txDecoded = Serialization . Transaction . fromCbor ( TxCBOR ( tx ) ) ;
@@ -438,6 +446,7 @@ const baseCip30WalletApi = (
438
446
const coreTx = txDecoded . toCore ( ) ;
439
447
const shouldProceed = await confirmationCallback
440
448
. signTx ( {
449
+ context,
441
450
data : coreTx ,
442
451
type : Cip30ConfirmationCallbackType . SignTx
443
452
} )
@@ -455,7 +464,7 @@ const baseCip30WalletApi = (
455
464
) ;
456
465
const {
457
466
witness : { signatures }
458
- } = await wallet . finalizeTx ( { tx : { ...coreTx , hash } } ) ;
467
+ } = await wallet . finalizeTx ( { origin : context . origin , tx : { ...coreTx , hash } } ) ;
459
468
460
469
// If partialSign is true, the wallet only tries to sign what it can. However, if
461
470
// signatures size is 0 then throw.
@@ -484,7 +493,7 @@ const baseCip30WalletApi = (
484
493
throw new TxSignError ( TxSignErrorCode . UserDeclined , 'user declined signing tx' ) ;
485
494
}
486
495
} ,
487
- submitTx : async ( input : Cbor ) : Promise < string > => {
496
+ submitTx : async ( _ : DAppConnectorContext , input : Cbor ) : Promise < string > => {
488
497
logger . debug ( 'submitting tx' ) ;
489
498
const { cbor, tx } = processTxInput ( input ) ;
490
499
const shouldProceed = await confirmationCallback
@@ -570,7 +579,7 @@ export const createWalletApi = (
570
579
wallet$ : Observable < ObservableWallet > ,
571
580
confirmationCallback : CallbackConfirmation ,
572
581
{ logger } : Cip30WalletDependencies
573
- ) : WalletApi => ( {
582
+ ) : WithDAppConnectorContext < WalletApi > => ( {
574
583
...baseCip30WalletApi ( wallet$ , confirmationCallback , { logger } ) ,
575
584
...extendedCip95WalletApi ( wallet$ , { logger } )
576
585
} ) ;
0 commit comments