1
1
import * as Crypto from '@cardano-sdk/crypto' ;
2
2
import { BlockfrostClient , BlockfrostProvider , fetchSequentially } from '../blockfrost' ;
3
- import { Cardano } from '@cardano-sdk/core' ;
4
- import { KeyPurpose } from '@cardano-sdk/key-management' ;
3
+ import { Cardano , Serialization } from '@cardano-sdk/core' ;
5
4
import { Logger } from 'ts-log' ;
6
5
import { MultiSigRegistration , MultiSigTransaction , SharedWalletProvider } from './types' ;
7
6
import type { Responses } from '@blockfrost/blockfrost-js' ;
8
7
9
- const MULTI_SIG_LABEL = KeyPurpose . MULTI_SIG ;
8
+ const MULTI_SIG_LABEL = 1854 ;
10
9
11
10
const isMultiSigRegistration = ( metadata : unknown ) : metadata is MultiSigRegistration =>
12
11
! ! metadata && typeof metadata === 'object' && 'participants' in metadata ;
@@ -16,10 +15,16 @@ export class BlockfrostSharedWalletProvider extends BlockfrostProvider implement
16
15
super ( client , logger ) ;
17
16
}
18
17
18
+ async getNativeScripts ( txId : Cardano . TransactionId ) : Promise < Cardano . Script [ ] > {
19
+ const response = await this . request < Responses [ 'tx_content_cbor' ] > ( `txs/${ txId } /cbor` ) ;
20
+ const transaction = Serialization . Transaction . fromCbor ( Serialization . TxCBOR ( response . cbor ) ) . toCore ( ) ;
21
+ return transaction . auxiliaryData ?. scripts ?? [ ] ;
22
+ }
23
+
19
24
async discoverWallets ( pubKey : Crypto . Ed25519KeyHashHex ) : Promise < MultiSigTransaction [ ] > {
20
25
const batchSize = 100 ;
21
26
22
- return fetchSequentially < Responses [ 'tx_metadata_label_json' ] [ 0 ] , MultiSigTransaction > (
27
+ const multiSigTransactions = await fetchSequentially < Responses [ 'tx_metadata_label_json' ] [ 0 ] , MultiSigTransaction > (
23
28
{
24
29
haveEnoughItems : ( wallets , _ ) => wallets . length < batchSize ,
25
30
paginationOptions : { count : batchSize } ,
@@ -35,10 +40,18 @@ export class BlockfrostSharedWalletProvider extends BlockfrostProvider implement
35
40
} )
36
41
. map ( ( wallet ) => ( {
37
42
metadata : wallet . json_metadata as unknown as MultiSigRegistration ,
43
+ nativeScripts : [ ] ,
38
44
txId : Cardano . TransactionId ( wallet . tx_hash )
39
45
} ) )
40
46
} ,
41
47
[ ]
42
48
) ;
49
+
50
+ return await Promise . all (
51
+ multiSigTransactions . map ( async ( wallet ) => ( {
52
+ ...wallet ,
53
+ nativeScripts : await this . getNativeScripts ( wallet . txId )
54
+ } ) )
55
+ ) ;
43
56
}
44
57
}
0 commit comments