@openzeppelin/guardian-client 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +140 -0
  2. package/dist/auth-request.d.ts +10 -0
  3. package/dist/auth-request.d.ts.map +1 -0
  4. package/dist/auth-request.js +38 -0
  5. package/dist/auth-request.js.map +1 -0
  6. package/dist/auth-request.test.d.ts +2 -0
  7. package/dist/auth-request.test.d.ts.map +1 -0
  8. package/dist/auth-request.test.js +10 -0
  9. package/dist/auth-request.test.js.map +1 -0
  10. package/dist/conversion.d.ts +18 -0
  11. package/dist/conversion.d.ts.map +1 -0
  12. package/dist/conversion.js +187 -0
  13. package/dist/conversion.js.map +1 -0
  14. package/dist/conversion.test.d.ts +2 -0
  15. package/dist/conversion.test.d.ts.map +1 -0
  16. package/dist/conversion.test.js +317 -0
  17. package/dist/conversion.test.js.map +1 -0
  18. package/dist/http.d.ts +33 -0
  19. package/dist/http.d.ts.map +1 -0
  20. package/dist/http.js +191 -0
  21. package/dist/http.js.map +1 -0
  22. package/dist/http.test.d.ts +2 -0
  23. package/dist/http.test.d.ts.map +1 -0
  24. package/dist/http.test.js +493 -0
  25. package/dist/http.test.js.map +1 -0
  26. package/dist/index.d.ts +4 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +3 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/server-types.d.ts +150 -0
  31. package/dist/server-types.d.ts.map +1 -0
  32. package/dist/server-types.js +2 -0
  33. package/dist/server-types.js.map +1 -0
  34. package/dist/types.d.ts +159 -0
  35. package/dist/types.d.ts.map +1 -0
  36. package/dist/types.js +2 -0
  37. package/dist/types.js.map +1 -0
  38. package/package.json +36 -0
  39. package/src/auth-request.test.ts +11 -0
  40. package/src/auth-request.ts +49 -0
  41. package/src/conversion.test.ts +400 -0
  42. package/src/conversion.ts +247 -0
  43. package/src/http.test.ts +597 -0
  44. package/src/http.ts +244 -0
  45. package/src/index.ts +25 -0
  46. package/src/server-types.ts +142 -0
  47. package/src/types.ts +167 -0
@@ -0,0 +1,400 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ fromServerCosignerSignature,
4
+ fromServerConfigureResponse,
5
+ fromServerDeltaObject,
6
+ fromServerDeltaStatus,
7
+ fromServerProposalMetadata,
8
+ fromServerStateObject,
9
+ toServerConfigureRequest,
10
+ toServerCosignerSignature,
11
+ toServerDeltaProposalRequest,
12
+ toServerDeltaStatus,
13
+ toServerExecutionDelta,
14
+ toServerProposalMetadata,
15
+ toServerSignProposalRequest,
16
+ } from './conversion.js';
17
+ import type {
18
+ ServerCosignerSignature,
19
+ ServerConfigureResponse,
20
+ ServerDeltaObject,
21
+ ServerDeltaStatus,
22
+ ServerProposalMetadata,
23
+ ServerStateObject,
24
+ } from './server-types.js';
25
+ import type {
26
+ CosignerSignature,
27
+ ConfigureRequest,
28
+ DeltaProposalRequest,
29
+ DeltaStatus,
30
+ ExecutionDelta,
31
+ ProposalMetadata,
32
+ SignProposalRequest,
33
+ } from './types.js';
34
+
35
+ describe('conversion', () => {
36
+ describe('fromServer conversions (server → camelCase)', () => {
37
+ it('converts CosignerSignature', () => {
38
+ const server: ServerCosignerSignature = {
39
+ signer_id: '0xabc',
40
+ signature: { scheme: 'falcon', signature: '0x123' },
41
+ timestamp: '2024-01-01T00:00:00Z',
42
+ };
43
+
44
+ const result = fromServerCosignerSignature(server);
45
+
46
+ expect(result).toEqual({
47
+ signerId: '0xabc',
48
+ signature: { scheme: 'falcon', signature: '0x123' },
49
+ timestamp: '2024-01-01T00:00:00Z',
50
+ });
51
+ });
52
+
53
+ it('converts pending DeltaStatus', () => {
54
+ const server: ServerDeltaStatus = {
55
+ status: 'pending',
56
+ timestamp: '2024-01-01T00:00:00Z',
57
+ proposer_id: '0xproposer',
58
+ cosigner_sigs: [
59
+ { signer_id: '0xsig1', signature: { scheme: 'falcon', signature: '0x1' }, timestamp: '2024-01-01T00:00:00Z' },
60
+ ],
61
+ };
62
+
63
+ const result = fromServerDeltaStatus(server);
64
+
65
+ expect(result).toEqual({
66
+ status: 'pending',
67
+ timestamp: '2024-01-01T00:00:00Z',
68
+ proposerId: '0xproposer',
69
+ cosignerSigs: [
70
+ { signerId: '0xsig1', signature: { scheme: 'falcon', signature: '0x1' }, timestamp: '2024-01-01T00:00:00Z' },
71
+ ],
72
+ });
73
+ });
74
+
75
+ it('converts candidate/canonical/discarded DeltaStatus', () => {
76
+ const statuses: ServerDeltaStatus[] = [
77
+ { status: 'candidate', timestamp: '2024-01-01T00:00:00Z' },
78
+ { status: 'canonical', timestamp: '2024-01-02T00:00:00Z' },
79
+ { status: 'discarded', timestamp: '2024-01-03T00:00:00Z' },
80
+ ];
81
+
82
+ for (const server of statuses) {
83
+ const result = fromServerDeltaStatus(server);
84
+ expect(result.status).toBe(server.status);
85
+ expect(result.timestamp).toBe(server.timestamp);
86
+ }
87
+ });
88
+
89
+ it('converts ProposalMetadata with all fields', () => {
90
+ const server: ServerProposalMetadata = {
91
+ proposal_type: 'update_procedure_threshold',
92
+ target_threshold: 2,
93
+ target_procedure: 'send_asset',
94
+ signer_commitments: ['0x1', '0x2'],
95
+ salt: '0xsalt',
96
+ description: 'test',
97
+ new_guardian_pubkey: '0xpubkey',
98
+ new_guardian_endpoint: 'http://guardian',
99
+ note_ids: ['0xnote1'],
100
+ recipient_id: '0xrecipient',
101
+ faucet_id: '0xfaucet',
102
+ amount: '1000',
103
+ };
104
+
105
+ const result = fromServerProposalMetadata(server);
106
+
107
+ expect(result).toEqual({
108
+ proposalType: 'update_procedure_threshold',
109
+ targetThreshold: 2,
110
+ targetProcedure: 'send_asset',
111
+ signerCommitments: ['0x1', '0x2'],
112
+ salt: '0xsalt',
113
+ description: 'test',
114
+ newGuardianPubkey: '0xpubkey',
115
+ newGuardianEndpoint: 'http://guardian',
116
+ noteIds: ['0xnote1'],
117
+ recipientId: '0xrecipient',
118
+ faucetId: '0xfaucet',
119
+ amount: '1000',
120
+ });
121
+ });
122
+
123
+ it('converts ProposalMetadata with partial fields', () => {
124
+ const server: ServerProposalMetadata = {
125
+ proposal_type: 'p2id',
126
+ description: 'send funds',
127
+ };
128
+
129
+ const result = fromServerProposalMetadata(server);
130
+
131
+ expect(result.proposalType).toBe('p2id');
132
+ expect(result.description).toBe('send funds');
133
+ expect(result.targetThreshold).toBeUndefined();
134
+ });
135
+
136
+ it('converts DeltaObject', () => {
137
+ const server: ServerDeltaObject = {
138
+ account_id: '0xaccount',
139
+ nonce: 1,
140
+ prev_commitment: '0xprev',
141
+ new_commitment: '0xnew',
142
+ delta_payload: {
143
+ tx_summary: { data: 'base64data' },
144
+ signatures: [{ signer_id: '0xsig', signature: { scheme: 'falcon', signature: '0x123' } }],
145
+ metadata: { proposal_type: 'add_signer', description: 'test' },
146
+ },
147
+ ack_sig: '0xack',
148
+ status: { status: 'canonical', timestamp: '2024-01-01T00:00:00Z' },
149
+ };
150
+
151
+ const result = fromServerDeltaObject(server);
152
+
153
+ expect(result.accountId).toBe('0xaccount');
154
+ expect(result.nonce).toBe(1);
155
+ expect(result.prevCommitment).toBe('0xprev');
156
+ expect(result.newCommitment).toBe('0xnew');
157
+ expect(result.deltaPayload.txSummary.data).toBe('base64data');
158
+ expect(result.deltaPayload.signatures[0].signerId).toBe('0xsig');
159
+ expect(result.deltaPayload.metadata?.proposalType).toBe('add_signer');
160
+ expect(result.ackSig).toBe('0xack');
161
+ expect(result.status.status).toBe('canonical');
162
+ });
163
+
164
+ it('converts DeltaObject without optional fields', () => {
165
+ const server: ServerDeltaObject = {
166
+ account_id: '0xaccount',
167
+ nonce: 1,
168
+ prev_commitment: '0xprev',
169
+ delta_payload: {
170
+ tx_summary: { data: 'base64data' },
171
+ signatures: [],
172
+ },
173
+ status: { status: 'pending', timestamp: '2024-01-01T00:00:00Z', proposer_id: '0xp', cosigner_sigs: [] },
174
+ };
175
+
176
+ const result = fromServerDeltaObject(server);
177
+
178
+ expect(result.newCommitment).toBeUndefined();
179
+ expect(result.deltaPayload.metadata).toBeUndefined();
180
+ expect(result.ackSig).toBeUndefined();
181
+ });
182
+
183
+ it('converts StateObject', () => {
184
+ const server: ServerStateObject = {
185
+ account_id: '0xaccount',
186
+ commitment: '0xcommit',
187
+ state_json: { data: 'statedata' },
188
+ created_at: '2024-01-01T00:00:00Z',
189
+ updated_at: '2024-01-02T00:00:00Z',
190
+ };
191
+
192
+ const result = fromServerStateObject(server);
193
+
194
+ expect(result).toEqual({
195
+ accountId: '0xaccount',
196
+ commitment: '0xcommit',
197
+ stateJson: { data: 'statedata' },
198
+ createdAt: '2024-01-01T00:00:00Z',
199
+ updatedAt: '2024-01-02T00:00:00Z',
200
+ });
201
+ });
202
+
203
+ it('converts ConfigureResponse', () => {
204
+ const server: ServerConfigureResponse = {
205
+ success: true,
206
+ message: 'configured',
207
+ ack_pubkey: '0xpubkey',
208
+ };
209
+
210
+ const result = fromServerConfigureResponse(server);
211
+
212
+ expect(result).toEqual({
213
+ success: true,
214
+ message: 'configured',
215
+ ackPubkey: '0xpubkey',
216
+ });
217
+ });
218
+ });
219
+
220
+ describe('toServer conversions (camelCase → server)', () => {
221
+ it('converts CosignerSignature', () => {
222
+ const sig: CosignerSignature = {
223
+ signerId: '0xabc',
224
+ signature: { scheme: 'falcon', signature: '0x123' },
225
+ timestamp: '2024-01-01T00:00:00Z',
226
+ };
227
+
228
+ const result = toServerCosignerSignature(sig);
229
+
230
+ expect(result).toEqual({
231
+ signer_id: '0xabc',
232
+ signature: { scheme: 'falcon', signature: '0x123' },
233
+ timestamp: '2024-01-01T00:00:00Z',
234
+ });
235
+ });
236
+
237
+ it('converts pending DeltaStatus', () => {
238
+ const status: DeltaStatus = {
239
+ status: 'pending',
240
+ timestamp: '2024-01-01T00:00:00Z',
241
+ proposerId: '0xproposer',
242
+ cosignerSigs: [
243
+ { signerId: '0xsig1', signature: { scheme: 'falcon', signature: '0x1' }, timestamp: '2024-01-01T00:00:00Z' },
244
+ ],
245
+ };
246
+
247
+ const result = toServerDeltaStatus(status);
248
+
249
+ expect(result).toEqual({
250
+ status: 'pending',
251
+ timestamp: '2024-01-01T00:00:00Z',
252
+ proposer_id: '0xproposer',
253
+ cosigner_sigs: [
254
+ { signer_id: '0xsig1', signature: { scheme: 'falcon', signature: '0x1' }, timestamp: '2024-01-01T00:00:00Z' },
255
+ ],
256
+ });
257
+ });
258
+
259
+ it('converts ProposalMetadata', () => {
260
+ const meta: ProposalMetadata = {
261
+ proposalType: 'update_procedure_threshold',
262
+ targetThreshold: 2,
263
+ targetProcedure: 'receive_asset',
264
+ signerCommitments: ['0x1', '0x2'],
265
+ salt: '0xsalt',
266
+ description: 'test',
267
+ };
268
+
269
+ const result = toServerProposalMetadata(meta);
270
+
271
+ expect(result).toEqual({
272
+ proposal_type: 'update_procedure_threshold',
273
+ target_threshold: 2,
274
+ target_procedure: 'receive_asset',
275
+ signer_commitments: ['0x1', '0x2'],
276
+ salt: '0xsalt',
277
+ description: 'test',
278
+ new_guardian_pubkey: undefined,
279
+ new_guardian_endpoint: undefined,
280
+ note_ids: undefined,
281
+ recipient_id: undefined,
282
+ faucet_id: undefined,
283
+ amount: undefined,
284
+ });
285
+ });
286
+
287
+ it('converts ConfigureRequest', () => {
288
+ const req: ConfigureRequest = {
289
+ accountId: '0xaccount',
290
+ auth: { MidenFalconRpo: { cosigner_commitments: ['0x1', '0x2'] } },
291
+ initialState: { data: 'statedata', accountId: '0xaccount' },
292
+ };
293
+
294
+ const result = toServerConfigureRequest(req);
295
+
296
+ expect(result).toEqual({
297
+ account_id: '0xaccount',
298
+ auth: { MidenFalconRpo: { cosigner_commitments: ['0x1', '0x2'] } },
299
+ initial_state: { data: 'statedata', account_id: '0xaccount' },
300
+ });
301
+ });
302
+
303
+ it('converts DeltaProposalRequest', () => {
304
+ const req: DeltaProposalRequest = {
305
+ accountId: '0xaccount',
306
+ nonce: 1,
307
+ deltaPayload: {
308
+ txSummary: { data: 'base64data' },
309
+ signatures: [{ signerId: '0xsig', signature: { scheme: 'falcon', signature: '0x123' } }],
310
+ metadata: { proposalType: 'add_signer', description: 'test' },
311
+ },
312
+ };
313
+
314
+ const result = toServerDeltaProposalRequest(req);
315
+
316
+ expect(result.account_id).toBe('0xaccount');
317
+ expect(result.nonce).toBe(1);
318
+ expect(result.delta_payload.tx_summary.data).toBe('base64data');
319
+ expect(result.delta_payload.signatures[0].signer_id).toBe('0xsig');
320
+ expect(result.delta_payload.metadata?.proposal_type).toBe('add_signer');
321
+ });
322
+
323
+ it('converts SignProposalRequest', () => {
324
+ const req: SignProposalRequest = {
325
+ accountId: '0xaccount',
326
+ commitment: '0xcommit',
327
+ signature: { scheme: 'falcon', signature: '0x123' },
328
+ };
329
+
330
+ const result = toServerSignProposalRequest(req);
331
+
332
+ expect(result).toEqual({
333
+ account_id: '0xaccount',
334
+ commitment: '0xcommit',
335
+ signature: { scheme: 'falcon', signature: '0x123' },
336
+ });
337
+ });
338
+
339
+ it('converts ExecutionDelta', () => {
340
+ const delta: ExecutionDelta = {
341
+ accountId: '0xaccount',
342
+ nonce: 1,
343
+ prevCommitment: '0xprev',
344
+ newCommitment: '0xnew',
345
+ deltaPayload: { data: 'base64data' },
346
+ ackSig: '0xack',
347
+ status: { status: 'canonical', timestamp: '2024-01-01T00:00:00Z' },
348
+ };
349
+
350
+ const result = toServerExecutionDelta(delta);
351
+
352
+ expect(result.account_id).toBe('0xaccount');
353
+ expect(result.nonce).toBe(1);
354
+ expect(result.prev_commitment).toBe('0xprev');
355
+ expect(result.new_commitment).toBe('0xnew');
356
+ expect(result.delta_payload.data).toBe('base64data');
357
+ expect(result.ack_sig).toBe('0xack');
358
+ expect(result.status.status).toBe('canonical');
359
+ });
360
+ });
361
+
362
+ describe('roundtrip conversions', () => {
363
+ it('DeltaStatus survives roundtrip', () => {
364
+ const original: DeltaStatus = {
365
+ status: 'pending',
366
+ timestamp: '2024-01-01T00:00:00Z',
367
+ proposerId: '0xproposer',
368
+ cosignerSigs: [
369
+ { signerId: '0xsig', signature: { scheme: 'falcon', signature: '0x123' }, timestamp: '2024-01-01T00:00:00Z' },
370
+ ],
371
+ };
372
+
373
+ const server = toServerDeltaStatus(original);
374
+ const result = fromServerDeltaStatus(server);
375
+
376
+ expect(result).toEqual(original);
377
+ });
378
+
379
+ it('ProposalMetadata survives roundtrip', () => {
380
+ const original: ProposalMetadata = {
381
+ proposalType: 'p2id',
382
+ description: 'send funds',
383
+ recipientId: '0xrecipient',
384
+ faucetId: '0xfaucet',
385
+ amount: '1000',
386
+ salt: '0xsalt',
387
+ };
388
+
389
+ const server = toServerProposalMetadata(original);
390
+ const result = fromServerProposalMetadata(server);
391
+
392
+ expect(result.proposalType).toBe(original.proposalType);
393
+ expect(result.description).toBe(original.description);
394
+ expect(result.recipientId).toBe(original.recipientId);
395
+ expect(result.faucetId).toBe(original.faucetId);
396
+ expect(result.amount).toBe(original.amount);
397
+ expect(result.salt).toBe(original.salt);
398
+ });
399
+ });
400
+ });
@@ -0,0 +1,247 @@
1
+ import type {
2
+ CosignerSignature,
3
+ ConfigureRequest,
4
+ ConfigureResponse,
5
+ DeltaObject,
6
+ DeltaProposalRequest,
7
+ DeltaStatus,
8
+ ExecutionDelta,
9
+ ProposalSignature,
10
+ ProposalMetadata,
11
+ SignProposalRequest,
12
+ StateObject,
13
+ } from './types.js';
14
+ import type {
15
+ ServerCosignerSignature,
16
+ ServerConfigureRequest,
17
+ ServerConfigureResponse,
18
+ ServerDeltaObject,
19
+ ServerDeltaProposalRequest,
20
+ ServerDeltaStatus,
21
+ ServerExecutionDelta,
22
+ ServerProposalSignature,
23
+ ServerProposalMetadata,
24
+ ServerSignProposalRequest,
25
+ ServerStateObject,
26
+ } from './server-types.js';
27
+
28
+ type ServerProposalDeltaPayload = {
29
+ tx_summary: { data: string };
30
+ signatures?: Array<{ signer_id: string; signature: ServerProposalSignature }>;
31
+ metadata?: ServerProposalMetadata;
32
+ };
33
+
34
+ type ServerExecutionDeltaPayload = {
35
+ data: string;
36
+ signatures?: Array<{ signer_id: string; signature: ServerProposalSignature }>;
37
+ metadata?: ServerProposalMetadata;
38
+ };
39
+
40
+ type ServerDeltaPayload = ServerProposalDeltaPayload | ServerExecutionDeltaPayload;
41
+
42
+ function extractDeltaPayload(payload: ServerDeltaPayload): {
43
+ txSummary: { data: string };
44
+ signatures: Array<{ signer_id: string; signature: ServerProposalSignature }>;
45
+ metadata?: ServerProposalMetadata;
46
+ } {
47
+ const txSummary = 'tx_summary' in payload ? payload.tx_summary : { data: payload.data };
48
+ const signatures = 'signatures' in payload && Array.isArray(payload.signatures) ? payload.signatures : [];
49
+ const metadata = 'metadata' in payload ? payload.metadata : undefined;
50
+ return { txSummary, signatures, metadata };
51
+ }
52
+
53
+ export function fromServerSignature(signature: ServerProposalSignature): ProposalSignature {
54
+ if (signature.scheme === 'ecdsa') {
55
+ return {
56
+ scheme: 'ecdsa',
57
+ signature: signature.signature,
58
+ publicKey: signature.public_key,
59
+ };
60
+ }
61
+ return signature;
62
+ }
63
+
64
+ export function fromServerCosignerSignature(server: ServerCosignerSignature): CosignerSignature {
65
+ return {
66
+ signerId: server.signer_id,
67
+ signature: fromServerSignature(server.signature),
68
+ timestamp: server.timestamp,
69
+ };
70
+ }
71
+
72
+ export function fromServerDeltaStatus(server: ServerDeltaStatus): DeltaStatus {
73
+ switch (server.status) {
74
+ case 'pending':
75
+ return {
76
+ status: 'pending',
77
+ timestamp: server.timestamp,
78
+ proposerId: server.proposer_id,
79
+ cosignerSigs: server.cosigner_sigs.map(fromServerCosignerSignature),
80
+ };
81
+ case 'candidate':
82
+ return { status: 'candidate', timestamp: server.timestamp };
83
+ case 'canonical':
84
+ return { status: 'canonical', timestamp: server.timestamp };
85
+ case 'discarded':
86
+ return { status: 'discarded', timestamp: server.timestamp };
87
+ }
88
+ }
89
+
90
+ export function fromServerProposalMetadata(server: ServerProposalMetadata): ProposalMetadata {
91
+ return {
92
+ proposalType: server.proposal_type,
93
+ targetThreshold: server.target_threshold,
94
+ requiredSignatures: server.required_signatures,
95
+ signerCommitments: server.signer_commitments,
96
+ targetProcedure: server.target_procedure,
97
+ salt: server.salt,
98
+ description: server.description,
99
+ newGuardianPubkey: server.new_guardian_pubkey,
100
+ newGuardianEndpoint: server.new_guardian_endpoint,
101
+ noteIds: server.note_ids,
102
+ recipientId: server.recipient_id,
103
+ faucetId: server.faucet_id,
104
+ amount: server.amount,
105
+ };
106
+ }
107
+
108
+ export function fromServerDeltaObject(server: ServerDeltaObject): DeltaObject {
109
+ const { txSummary, signatures, metadata } = extractDeltaPayload(server.delta_payload as ServerDeltaPayload);
110
+
111
+ return {
112
+ accountId: server.account_id,
113
+ nonce: server.nonce,
114
+ prevCommitment: server.prev_commitment,
115
+ newCommitment: server.new_commitment,
116
+ deltaPayload: {
117
+ txSummary,
118
+ signatures: signatures.map((s) => ({
119
+ signerId: s.signer_id,
120
+ signature: fromServerSignature(s.signature),
121
+ })),
122
+ metadata: metadata ? fromServerProposalMetadata(metadata) : undefined,
123
+ },
124
+ ackSig: server.ack_sig,
125
+ ackPubkey: server.ack_pubkey,
126
+ ackScheme: server.ack_scheme,
127
+ status: fromServerDeltaStatus(server.status),
128
+ };
129
+ }
130
+
131
+ export function fromServerStateObject(server: ServerStateObject): StateObject {
132
+ return {
133
+ accountId: server.account_id,
134
+ commitment: server.commitment,
135
+ stateJson: server.state_json,
136
+ createdAt: server.created_at,
137
+ updatedAt: server.updated_at,
138
+ authScheme: server.auth_scheme,
139
+ };
140
+ }
141
+
142
+ export function fromServerConfigureResponse(server: ServerConfigureResponse): ConfigureResponse {
143
+ return {
144
+ success: server.success,
145
+ message: server.message,
146
+ ackPubkey: server.ack_pubkey,
147
+ ackCommitment: server.ack_commitment,
148
+ };
149
+ }
150
+
151
+ export function toServerSignature(sig: ProposalSignature): ServerProposalSignature {
152
+ if (sig.scheme === 'ecdsa') {
153
+ return {
154
+ scheme: 'ecdsa',
155
+ signature: sig.signature,
156
+ public_key: sig.publicKey,
157
+ };
158
+ }
159
+ return sig;
160
+ }
161
+
162
+ export function toServerCosignerSignature(sig: CosignerSignature): ServerCosignerSignature {
163
+ return {
164
+ signer_id: sig.signerId,
165
+ signature: toServerSignature(sig.signature),
166
+ timestamp: sig.timestamp,
167
+ };
168
+ }
169
+
170
+ export function toServerDeltaStatus(status: DeltaStatus): ServerDeltaStatus {
171
+ switch (status.status) {
172
+ case 'pending':
173
+ return {
174
+ status: 'pending',
175
+ timestamp: status.timestamp,
176
+ proposer_id: status.proposerId,
177
+ cosigner_sigs: status.cosignerSigs.map(toServerCosignerSignature),
178
+ };
179
+ case 'candidate':
180
+ return { status: 'candidate', timestamp: status.timestamp };
181
+ case 'canonical':
182
+ return { status: 'canonical', timestamp: status.timestamp };
183
+ case 'discarded':
184
+ return { status: 'discarded', timestamp: status.timestamp };
185
+ }
186
+ }
187
+
188
+ export function toServerProposalMetadata(meta: ProposalMetadata): ServerProposalMetadata {
189
+ return {
190
+ proposal_type: meta.proposalType === 'unknown' ? undefined : meta.proposalType,
191
+ target_threshold: meta.targetThreshold,
192
+ required_signatures: meta.requiredSignatures,
193
+ signer_commitments: meta.signerCommitments,
194
+ target_procedure: meta.targetProcedure,
195
+ salt: meta.salt,
196
+ description: meta.description,
197
+ new_guardian_pubkey: meta.newGuardianPubkey,
198
+ new_guardian_endpoint: meta.newGuardianEndpoint,
199
+ note_ids: meta.noteIds,
200
+ recipient_id: meta.recipientId,
201
+ faucet_id: meta.faucetId,
202
+ amount: meta.amount,
203
+ };
204
+ }
205
+
206
+ export function toServerConfigureRequest(req: ConfigureRequest): ServerConfigureRequest {
207
+ return {
208
+ account_id: req.accountId,
209
+ auth: req.auth,
210
+ initial_state: { data: req.initialState.data, account_id: req.initialState.accountId },
211
+ };
212
+ }
213
+
214
+ export function toServerDeltaProposalRequest(req: DeltaProposalRequest): ServerDeltaProposalRequest {
215
+ return {
216
+ account_id: req.accountId,
217
+ nonce: req.nonce,
218
+ delta_payload: {
219
+ tx_summary: req.deltaPayload.txSummary,
220
+ signatures: req.deltaPayload.signatures.map((s) => ({
221
+ signer_id: s.signerId,
222
+ signature: toServerSignature(s.signature),
223
+ })),
224
+ metadata: req.deltaPayload.metadata ? toServerProposalMetadata(req.deltaPayload.metadata) : undefined,
225
+ },
226
+ };
227
+ }
228
+
229
+ export function toServerSignProposalRequest(req: SignProposalRequest): ServerSignProposalRequest {
230
+ return {
231
+ account_id: req.accountId,
232
+ commitment: req.commitment,
233
+ signature: toServerSignature(req.signature),
234
+ };
235
+ }
236
+
237
+ export function toServerExecutionDelta(delta: ExecutionDelta): ServerExecutionDelta {
238
+ return {
239
+ account_id: delta.accountId,
240
+ nonce: delta.nonce,
241
+ prev_commitment: delta.prevCommitment,
242
+ new_commitment: delta.newCommitment,
243
+ delta_payload: delta.deltaPayload,
244
+ ack_sig: delta.ackSig,
245
+ status: toServerDeltaStatus(delta.status),
246
+ };
247
+ }