Skip to content

Commit bbca483

Browse files
authored
feat: pass userId to all blockdaemon endpoints (#1183)
Signed-off-by: Marc Juchli <marc.juchli@digitalasset.com>
1 parent ad920d1 commit bbca483

File tree

2 files changed

+144
-1
lines changed

2 files changed

+144
-1
lines changed

core/signing-blockdaemon/src/index.test.ts

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { jest, expect, describe, test, beforeEach } from '@jest/globals'
55
import BlockdaemonSigningDriver from './index.js'
66
import { SigningAPIClient } from './signing-api-sdk.js'
7-
import { Transaction } from '@canton-network/core-signing-lib'
7+
import { Transaction, Key } from '@canton-network/core-signing-lib'
88

99
describe('BlockdaemonSigningDriver', () => {
1010
const config = {
@@ -21,6 +21,10 @@ describe('BlockdaemonSigningDriver', () => {
2121

2222
mockClient = {
2323
signTransaction: jest.fn(),
24+
getTransaction: jest.fn(),
25+
getTransactions: jest.fn(),
26+
getKeys: jest.fn(),
27+
createKey: jest.fn(),
2428
} as unknown as jest.Mocked<SigningAPIClient>
2529

2630
driver = new BlockdaemonSigningDriver(config)
@@ -67,4 +71,139 @@ describe('BlockdaemonSigningDriver', () => {
6771
publicKey: mockResponse.publicKey,
6872
})
6973
})
74+
75+
test('createKey calls client.createKey with correct params', async () => {
76+
const createKeyParams = {
77+
name: 'new-key',
78+
}
79+
80+
const mockResponse = {
81+
id: 'key-id',
82+
name: 'new-key',
83+
publicKey: 'new-public-key',
84+
}
85+
86+
mockClient.createKey.mockResolvedValue(mockResponse as Key)
87+
88+
const result = await driver
89+
.controller(userId)
90+
.createKey(createKeyParams)
91+
92+
expect(mockClient.createKey).toHaveBeenCalledWith({
93+
name: createKeyParams.name,
94+
userIdentifier: userId,
95+
})
96+
97+
expect(result).toEqual({
98+
id: mockResponse.id,
99+
name: mockResponse.name,
100+
publicKey: mockResponse.publicKey,
101+
})
102+
})
103+
104+
test('getTransaction calls client.getTransaction with correct params', async () => {
105+
const getTransactionParams = {
106+
txId: 'tx-id',
107+
}
108+
109+
const mockResponse = {
110+
txId: 'tx-id',
111+
status: 'signed',
112+
signature: 'signature-bytes',
113+
publicKey: 'some-public-key',
114+
}
115+
116+
mockClient.getTransaction.mockResolvedValue(mockResponse as Transaction)
117+
118+
const result = await driver
119+
.controller(userId)
120+
.getTransaction(getTransactionParams)
121+
122+
expect(mockClient.getTransaction).toHaveBeenCalledWith({
123+
txId: getTransactionParams.txId,
124+
userIdentifier: userId,
125+
})
126+
127+
expect(result).toEqual({
128+
txId: mockResponse.txId,
129+
status: mockResponse.status,
130+
signature: mockResponse.signature,
131+
publicKey: mockResponse.publicKey,
132+
})
133+
})
134+
135+
test('getTransactions calls client.getTransactions with correct params', async () => {
136+
const getTransactionsParams = {
137+
txIds: ['tx-id-1', 'tx-id-2'],
138+
publicKeys: ['pk-1'],
139+
}
140+
141+
const mockResponse = [
142+
{
143+
txId: 'tx-id-1',
144+
status: 'signed',
145+
signature: 'sig-1',
146+
publicKey: 'pk-1',
147+
},
148+
{
149+
txId: 'tx-id-2',
150+
status: 'pending',
151+
signature: 'sig-2',
152+
publicKey: 'pk-1',
153+
},
154+
]
155+
156+
mockClient.getTransactions.mockResolvedValue(
157+
mockResponse as Transaction[]
158+
)
159+
160+
const result = await driver
161+
.controller(userId)
162+
.getTransactions(getTransactionsParams)
163+
164+
expect(mockClient.getTransactions).toHaveBeenCalledWith({
165+
txIds: getTransactionsParams.txIds,
166+
publicKeys: getTransactionsParams.publicKeys,
167+
userIdentifier: userId,
168+
})
169+
170+
expect(result).toEqual({
171+
transactions: mockResponse.map((tx) => ({
172+
txId: tx.txId,
173+
status: tx.status,
174+
signature: tx.signature,
175+
publicKey: tx.publicKey,
176+
})),
177+
})
178+
})
179+
180+
test('getKeys calls client.getKeys with correct params', async () => {
181+
const mockResponse = [
182+
{
183+
id: 'key-1',
184+
name: 'Key 1',
185+
publicKey: 'pk-1',
186+
},
187+
{
188+
id: 'key-2',
189+
name: 'Key 2',
190+
publicKey: 'pk-2',
191+
},
192+
]
193+
194+
mockClient.getKeys.mockResolvedValue(mockResponse as Key[])
195+
196+
const result = await driver.controller(userId).getKeys()
197+
198+
expect(mockClient.getKeys).toHaveBeenCalled()
199+
200+
expect(result).toEqual({
201+
keys: mockResponse.map((k) => ({
202+
id: k.id,
203+
name: k.name,
204+
publicKey: k.publicKey,
205+
userIdentifier: userId,
206+
})),
207+
})
208+
})
70209
})

core/signing-blockdaemon/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default class BlockdaemonSigningDriver implements SigningDriverInterface
8888
try {
8989
const tx = await this.client.getTransaction({
9090
txId: params.txId,
91+
userIdentifier: userId,
9192
})
9293
return {
9394
txId: tx.txId,
@@ -115,6 +116,7 @@ export default class BlockdaemonSigningDriver implements SigningDriverInterface
115116
const transactions = await this.client.getTransactions({
116117
txIds: params.txIds!,
117118
publicKeys: params.publicKeys!,
119+
userIdentifier: userId,
118120
})
119121
return {
120122
transactions: transactions.map((tx) => ({
@@ -147,6 +149,7 @@ export default class BlockdaemonSigningDriver implements SigningDriverInterface
147149
id: k.id,
148150
name: k.name,
149151
publicKey: k.publicKey,
152+
userIdentifier: userId,
150153
})),
151154
}
152155
} catch (error) {
@@ -163,6 +166,7 @@ export default class BlockdaemonSigningDriver implements SigningDriverInterface
163166
try {
164167
const key = await this.client.createKey({
165168
name: params.name,
169+
userIdentifier: userId,
166170
})
167171
return {
168172
id: key.id,

0 commit comments

Comments
 (0)