Skip to content

Commit 99c73fc

Browse files
committed
fixup! feat: discover shared wallet by metadata label
1 parent cfcbae8 commit 99c73fc

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

packages/cardano-services-client/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"dependencies": {
6060
"@cardano-sdk/core": "workspace:~",
6161
"@cardano-sdk/crypto": "workspace:~",
62-
"@cardano-sdk/key-management": "workspace:~",
6362
"@cardano-sdk/util": "workspace:~",
6463
"axios": "^1.7.4",
6564
"class-validator": "^0.14.0",

packages/cardano-services-client/src/SharedWalletProvider/BlockfrostSharedWalletProvider.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import * as Crypto from '@cardano-sdk/crypto';
22
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';
54
import { Logger } from 'ts-log';
65
import { MultiSigRegistration, MultiSigTransaction, SharedWalletProvider } from './types';
76
import type { Responses } from '@blockfrost/blockfrost-js';
87

9-
const MULTI_SIG_LABEL = KeyPurpose.MULTI_SIG;
8+
const MULTI_SIG_LABEL = 1854;
109

1110
const isMultiSigRegistration = (metadata: unknown): metadata is MultiSigRegistration =>
1211
!!metadata && typeof metadata === 'object' && 'participants' in metadata;
@@ -16,10 +15,16 @@ export class BlockfrostSharedWalletProvider extends BlockfrostProvider implement
1615
super(client, logger);
1716
}
1817

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+
1924
async discoverWallets(pubKey: Crypto.Ed25519KeyHashHex): Promise<MultiSigTransaction[]> {
2025
const batchSize = 100;
2126

22-
return fetchSequentially<Responses['tx_metadata_label_json'][0], MultiSigTransaction>(
27+
const multiSigTransactions = await fetchSequentially<Responses['tx_metadata_label_json'][0], MultiSigTransaction>(
2328
{
2429
haveEnoughItems: (wallets, _) => wallets.length < batchSize,
2530
paginationOptions: { count: batchSize },
@@ -35,10 +40,18 @@ export class BlockfrostSharedWalletProvider extends BlockfrostProvider implement
3540
})
3641
.map((wallet) => ({
3742
metadata: wallet.json_metadata as unknown as MultiSigRegistration,
43+
nativeScripts: [],
3844
txId: Cardano.TransactionId(wallet.tx_hash)
3945
}))
4046
},
4147
[]
4248
);
49+
50+
return await Promise.all(
51+
multiSigTransactions.map(async (wallet) => ({
52+
...wallet,
53+
nativeScripts: await this.getNativeScripts(wallet.txId)
54+
}))
55+
);
4356
}
4457
}

packages/cardano-services-client/src/SharedWalletProvider/types.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Cardano } from '@cardano-sdk/core';
22
import { Ed25519KeyHashHex } from '@cardano-sdk/crypto';
3-
import { KeyRole } from '@cardano-sdk/key-management';
43

5-
type ScriptType = KeyRole;
4+
type ScriptType = number;
65

76
interface MultiSigParticipant {
87
name: string;
@@ -25,7 +24,7 @@ export interface MultiSigRegistration {
2524
export interface MultiSigTransaction {
2625
txId: Cardano.TransactionId;
2726
metadata: MultiSigRegistration;
28-
nativeScripts?: Cardano.NativeScript[];
27+
nativeScripts?: Cardano.Script[];
2928
}
3029

3130
export interface SharedWalletProvider {

packages/cardano-services-client/test/SharedWalletProvider/BlockfrostSharedWallet.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ const mockedResponses = [
132132
}
133133
];
134134

135+
const nativeScriptResponse = {
136+
cbor: '84a70081825820765bf5499431711696c37ce98cf5b40b94e592ae497c7e1acadf44e97db540de0001818258390029fb060929ae397acd22105b8d512cafbe14beb372b7940734c8e0a049ffdf3c964ec375208a6b46cc6075ad36beb80bcce21663021d78da1a004caf43021a0002d611031a04850a6905a1581de049ffdf3c964ec375208a6b46cc6075ad36beb80bcce21663021d78da1a0005ee750758200e0397a8285695c5f5a581b4cfca2896ecdcab79e1723b36ba0b3904cc8ad04f0800a100828258202ebc0ea3cd6546b9e1c82c8f14a9d59e1f21a8483453e2bce5e1aa9fb5cd37bb5840cefb6d1f99e7ef1d72f2a67779764832949d10b1f62e08602b8bba50da703fe36c91f192e2fd60d709fc027b964979ac6197da708091b591c75e5e21b770b500825820520b5cd3b967df70972451885c54de299738ead98113080130848b39cea2854e5840f092b42091f16082a34789c45471ab1f60ee175fe752ce29f7c42edea6c04151c8c47bf684f53bdefd765de0f2dba9fc1f8e914f29b97c8fae6cc7727465c006f582a119073ea46b6465736372697074696f6e7064206d622d732b6c6e782b746d743032646e616d656e6d622d732b6c6e782b746d7430326c7061727469636970616e7473a065747970657382677061796d656e74657374616b65828202838200581ce3ad78d912029930ec11394610bdd4dd12bc64effb61e2258ab059338200581c8a7c43db68954f99e8afa35130ac65576776eb6500d2c616cb6d1d408200581c83dec074a40f7d6b7cfd902243ec4b902d17960a69a66acd8bd35ce08202838200581c96f941682e4b1873dc45ef6930378915ae637c5be5d6c1fd1f9491e68200581c734a5efd35afe4de6a9bf2ca4c4bfe2a22b370a0acbddd9c3dfbfa6b8200581cd8747c9c7d51385172474bfea67ecdb27eaf9bb5be216118b407775b'
137+
};
138+
135139
describe('BlockfrostSharedWallet', () => {
136140
let request: jest.Mock;
137141
let provider: BlockfrostSharedWalletProvider;
@@ -152,11 +156,19 @@ describe('BlockfrostSharedWallet', () => {
152156

153157
it('should return all wallets for a given public key', async () => {
154158
request.mockResolvedValueOnce(mockedResponses);
159+
160+
request
161+
.mockResolvedValueOnce(nativeScriptResponse)
162+
.mockResolvedValueOnce(nativeScriptResponse)
163+
.mockResolvedValueOnce(nativeScriptResponse);
164+
155165
const pubKey = '962746268ee907e18c895c9943c6684b01fa7a4956b0fe0fa76cfa6f';
156166
const wallets = await provider.discoverWallets(Crypto.Ed25519KeyHashHex(pubKey));
167+
157168
expect(wallets.length).toEqual(3);
158169
for (const wallet of wallets) {
159170
expect(wallet.metadata.participants).toHaveProperty(pubKey);
171+
expect(wallet.nativeScripts).toHaveLength(2);
160172
}
161173
});
162174
});

packages/core/test/Serialization/Transaction.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ describe('Transaction', () => {
8686
expect(tx3.body().toCbor()).toEqual(tx2.body().toCbor());
8787
});
8888

89+
it('serializationTest', () => {
90+
const cbor =
91+
'84a70081825820765bf5499431711696c37ce98cf5b40b94e592ae497c7e1acadf44e97db540de0001818258390029fb060929ae397acd22105b8d512cafbe14beb372b7940734c8e0a049ffdf3c964ec375208a6b46cc6075ad36beb80bcce21663021d78da1a004caf43021a0002d611031a04850a6905a1581de049ffdf3c964ec375208a6b46cc6075ad36beb80bcce21663021d78da1a0005ee750758200e0397a8285695c5f5a581b4cfca2896ecdcab79e1723b36ba0b3904cc8ad04f0800a100828258202ebc0ea3cd6546b9e1c82c8f14a9d59e1f21a8483453e2bce5e1aa9fb5cd37bb5840cefb6d1f99e7ef1d72f2a67779764832949d10b1f62e08602b8bba50da703fe36c91f192e2fd60d709fc027b964979ac6197da708091b591c75e5e21b770b500825820520b5cd3b967df70972451885c54de299738ead98113080130848b39cea2854e5840f092b42091f16082a34789c45471ab1f60ee175fe752ce29f7c42edea6c04151c8c47bf684f53bdefd765de0f2dba9fc1f8e914f29b97c8fae6cc7727465c006f582a119073ea46b6465736372697074696f6e7064206d622d732b6c6e782b746d743032646e616d656e6d622d732b6c6e782b746d7430326c7061727469636970616e7473a065747970657382677061796d656e74657374616b65828202838200581ce3ad78d912029930ec11394610bdd4dd12bc64effb61e2258ab059338200581c8a7c43db68954f99e8afa35130ac65576776eb6500d2c616cb6d1d408200581c83dec074a40f7d6b7cfd902243ec4b902d17960a69a66acd8bd35ce08202838200581c96f941682e4b1873dc45ef6930378915ae637c5be5d6c1fd1f9491e68200581c734a5efd35afe4de6a9bf2ca4c4bfe2a22b370a0acbddd9c3dfbfa6b8200581cd8747c9c7d51385172474bfea67ecdb27eaf9bb5be216118b407775b';
92+
const tx = Transaction.fromCbor(TxCBOR(cbor)).toCore();
93+
expect(tx).toBeDefined();
94+
});
95+
8996
it('can set the witness set on the transaction', () => {
9097
const tx = Transaction.fromCbor(TxCBOR(TX));
9198
const tx2 = Transaction.fromCbor(TxCBOR(TX2));

yarn.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3389,7 +3389,6 @@ __metadata:
33893389
"@blockfrost/blockfrost-js": ^5.7.0
33903390
"@cardano-sdk/core": "workspace:~"
33913391
"@cardano-sdk/crypto": "workspace:~"
3392-
"@cardano-sdk/key-management": "workspace:~"
33933392
"@cardano-sdk/util": "workspace:~"
33943393
"@cardano-sdk/util-dev": "workspace:~"
33953394
"@types/lodash": ^4.14.182

0 commit comments

Comments
 (0)