@buildonspark/issuer-sdk 0.0.30 → 0.0.31
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.
- package/dist/index.cjs +31 -39
- package/dist/index.d.cts +17 -9
- package/dist/index.d.ts +17 -9
- package/dist/index.js +31 -39
- package/package.json +3 -2
- package/src/index.ts +1 -1
- package/src/issuer-spark-wallet.ts +39 -28
- package/src/proto/common.ts +91 -38
- package/src/proto/google/protobuf/descriptor.ts +2308 -1439
- package/src/proto/google/protobuf/duration.ts +28 -10
- package/src/proto/google/protobuf/empty.ts +24 -10
- package/src/proto/google/protobuf/timestamp.ts +28 -10
- package/src/proto/mock.ts +84 -54
- package/src/proto/spark.ts +9718 -7485
- package/src/proto/spark_authn.ts +165 -60
- package/src/proto/validate/validate.ts +1157 -661
- package/src/services/token-transactions.ts +2 -2
- package/src/tests/integration/spark.test.ts +11 -82
- package/src/tests/stress/transfers.test.ts +101 -10
- package/src/types.ts +73 -70
- package/src/utils/enum-mappers.ts +16 -5
- package/src/utils/token-hashing.ts +2 -2
- package/src/utils/type-mappers.ts +136 -103
package/src/proto/spark_authn.ts
CHANGED
|
@@ -27,9 +27,7 @@ export interface ProtectedChallenge {
|
|
|
27
27
|
/** Protocol version for backward compatibility */
|
|
28
28
|
version: number;
|
|
29
29
|
/** The core challenge data */
|
|
30
|
-
challenge:
|
|
31
|
-
| Challenge
|
|
32
|
-
| undefined;
|
|
30
|
+
challenge: Challenge | undefined;
|
|
33
31
|
/** Server's HMAC of the Challenge */
|
|
34
32
|
serverHmac: Uint8Array;
|
|
35
33
|
}
|
|
@@ -49,9 +47,7 @@ export interface GetChallengeResponse {
|
|
|
49
47
|
/** Request to verify a signed challenge */
|
|
50
48
|
export interface VerifyChallengeRequest {
|
|
51
49
|
/** The protected challenge from the server */
|
|
52
|
-
protectedChallenge:
|
|
53
|
-
| ProtectedChallenge
|
|
54
|
-
| undefined;
|
|
50
|
+
protectedChallenge: ProtectedChallenge | undefined;
|
|
55
51
|
/** Client's secp256k1 signature of the Challenge */
|
|
56
52
|
signature: Uint8Array;
|
|
57
53
|
/** Client's public key (uncompressed secp256k1 public key) */
|
|
@@ -67,11 +63,19 @@ export interface VerifyChallengeResponse {
|
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
function createBaseChallenge(): Challenge {
|
|
70
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
version: 0,
|
|
68
|
+
timestamp: 0,
|
|
69
|
+
nonce: new Uint8Array(0),
|
|
70
|
+
publicKey: new Uint8Array(0),
|
|
71
|
+
};
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
export const Challenge: MessageFns<Challenge> = {
|
|
74
|
-
encode(
|
|
75
|
+
encode(
|
|
76
|
+
message: Challenge,
|
|
77
|
+
writer: BinaryWriter = new BinaryWriter(),
|
|
78
|
+
): BinaryWriter {
|
|
75
79
|
if (message.version !== 0) {
|
|
76
80
|
writer.uint32(8).int32(message.version);
|
|
77
81
|
}
|
|
@@ -88,7 +92,8 @@ export const Challenge: MessageFns<Challenge> = {
|
|
|
88
92
|
},
|
|
89
93
|
|
|
90
94
|
decode(input: BinaryReader | Uint8Array, length?: number): Challenge {
|
|
91
|
-
const reader =
|
|
95
|
+
const reader =
|
|
96
|
+
input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
92
97
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
93
98
|
const message = createBaseChallenge();
|
|
94
99
|
while (reader.pos < end) {
|
|
@@ -138,9 +143,15 @@ export const Challenge: MessageFns<Challenge> = {
|
|
|
138
143
|
fromJSON(object: any): Challenge {
|
|
139
144
|
return {
|
|
140
145
|
version: isSet(object.version) ? globalThis.Number(object.version) : 0,
|
|
141
|
-
timestamp: isSet(object.timestamp)
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
timestamp: isSet(object.timestamp)
|
|
147
|
+
? globalThis.Number(object.timestamp)
|
|
148
|
+
: 0,
|
|
149
|
+
nonce: isSet(object.nonce)
|
|
150
|
+
? bytesFromBase64(object.nonce)
|
|
151
|
+
: new Uint8Array(0),
|
|
152
|
+
publicKey: isSet(object.publicKey)
|
|
153
|
+
? bytesFromBase64(object.publicKey)
|
|
154
|
+
: new Uint8Array(0),
|
|
144
155
|
};
|
|
145
156
|
},
|
|
146
157
|
|
|
@@ -179,7 +190,10 @@ function createBaseProtectedChallenge(): ProtectedChallenge {
|
|
|
179
190
|
}
|
|
180
191
|
|
|
181
192
|
export const ProtectedChallenge: MessageFns<ProtectedChallenge> = {
|
|
182
|
-
encode(
|
|
193
|
+
encode(
|
|
194
|
+
message: ProtectedChallenge,
|
|
195
|
+
writer: BinaryWriter = new BinaryWriter(),
|
|
196
|
+
): BinaryWriter {
|
|
183
197
|
if (message.version !== 0) {
|
|
184
198
|
writer.uint32(8).int32(message.version);
|
|
185
199
|
}
|
|
@@ -192,8 +206,12 @@ export const ProtectedChallenge: MessageFns<ProtectedChallenge> = {
|
|
|
192
206
|
return writer;
|
|
193
207
|
},
|
|
194
208
|
|
|
195
|
-
decode(
|
|
196
|
-
|
|
209
|
+
decode(
|
|
210
|
+
input: BinaryReader | Uint8Array,
|
|
211
|
+
length?: number,
|
|
212
|
+
): ProtectedChallenge {
|
|
213
|
+
const reader =
|
|
214
|
+
input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
197
215
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
198
216
|
const message = createBaseProtectedChallenge();
|
|
199
217
|
while (reader.pos < end) {
|
|
@@ -235,8 +253,12 @@ export const ProtectedChallenge: MessageFns<ProtectedChallenge> = {
|
|
|
235
253
|
fromJSON(object: any): ProtectedChallenge {
|
|
236
254
|
return {
|
|
237
255
|
version: isSet(object.version) ? globalThis.Number(object.version) : 0,
|
|
238
|
-
challenge: isSet(object.challenge)
|
|
239
|
-
|
|
256
|
+
challenge: isSet(object.challenge)
|
|
257
|
+
? Challenge.fromJSON(object.challenge)
|
|
258
|
+
: undefined,
|
|
259
|
+
serverHmac: isSet(object.serverHmac)
|
|
260
|
+
? bytesFromBase64(object.serverHmac)
|
|
261
|
+
: new Uint8Array(0),
|
|
240
262
|
};
|
|
241
263
|
},
|
|
242
264
|
|
|
@@ -260,9 +282,10 @@ export const ProtectedChallenge: MessageFns<ProtectedChallenge> = {
|
|
|
260
282
|
fromPartial(object: DeepPartial<ProtectedChallenge>): ProtectedChallenge {
|
|
261
283
|
const message = createBaseProtectedChallenge();
|
|
262
284
|
message.version = object.version ?? 0;
|
|
263
|
-
message.challenge =
|
|
264
|
-
|
|
265
|
-
|
|
285
|
+
message.challenge =
|
|
286
|
+
object.challenge !== undefined && object.challenge !== null
|
|
287
|
+
? Challenge.fromPartial(object.challenge)
|
|
288
|
+
: undefined;
|
|
266
289
|
message.serverHmac = object.serverHmac ?? new Uint8Array(0);
|
|
267
290
|
return message;
|
|
268
291
|
},
|
|
@@ -273,15 +296,22 @@ function createBaseGetChallengeRequest(): GetChallengeRequest {
|
|
|
273
296
|
}
|
|
274
297
|
|
|
275
298
|
export const GetChallengeRequest: MessageFns<GetChallengeRequest> = {
|
|
276
|
-
encode(
|
|
299
|
+
encode(
|
|
300
|
+
message: GetChallengeRequest,
|
|
301
|
+
writer: BinaryWriter = new BinaryWriter(),
|
|
302
|
+
): BinaryWriter {
|
|
277
303
|
if (message.publicKey.length !== 0) {
|
|
278
304
|
writer.uint32(10).bytes(message.publicKey);
|
|
279
305
|
}
|
|
280
306
|
return writer;
|
|
281
307
|
},
|
|
282
308
|
|
|
283
|
-
decode(
|
|
284
|
-
|
|
309
|
+
decode(
|
|
310
|
+
input: BinaryReader | Uint8Array,
|
|
311
|
+
length?: number,
|
|
312
|
+
): GetChallengeRequest {
|
|
313
|
+
const reader =
|
|
314
|
+
input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
285
315
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
286
316
|
const message = createBaseGetChallengeRequest();
|
|
287
317
|
while (reader.pos < end) {
|
|
@@ -305,7 +335,11 @@ export const GetChallengeRequest: MessageFns<GetChallengeRequest> = {
|
|
|
305
335
|
},
|
|
306
336
|
|
|
307
337
|
fromJSON(object: any): GetChallengeRequest {
|
|
308
|
-
return {
|
|
338
|
+
return {
|
|
339
|
+
publicKey: isSet(object.publicKey)
|
|
340
|
+
? bytesFromBase64(object.publicKey)
|
|
341
|
+
: new Uint8Array(0),
|
|
342
|
+
};
|
|
309
343
|
},
|
|
310
344
|
|
|
311
345
|
toJSON(message: GetChallengeRequest): unknown {
|
|
@@ -331,15 +365,25 @@ function createBaseGetChallengeResponse(): GetChallengeResponse {
|
|
|
331
365
|
}
|
|
332
366
|
|
|
333
367
|
export const GetChallengeResponse: MessageFns<GetChallengeResponse> = {
|
|
334
|
-
encode(
|
|
368
|
+
encode(
|
|
369
|
+
message: GetChallengeResponse,
|
|
370
|
+
writer: BinaryWriter = new BinaryWriter(),
|
|
371
|
+
): BinaryWriter {
|
|
335
372
|
if (message.protectedChallenge !== undefined) {
|
|
336
|
-
ProtectedChallenge.encode(
|
|
373
|
+
ProtectedChallenge.encode(
|
|
374
|
+
message.protectedChallenge,
|
|
375
|
+
writer.uint32(10).fork(),
|
|
376
|
+
).join();
|
|
337
377
|
}
|
|
338
378
|
return writer;
|
|
339
379
|
},
|
|
340
380
|
|
|
341
|
-
decode(
|
|
342
|
-
|
|
381
|
+
decode(
|
|
382
|
+
input: BinaryReader | Uint8Array,
|
|
383
|
+
length?: number,
|
|
384
|
+
): GetChallengeResponse {
|
|
385
|
+
const reader =
|
|
386
|
+
input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
343
387
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
344
388
|
const message = createBaseGetChallengeResponse();
|
|
345
389
|
while (reader.pos < end) {
|
|
@@ -350,7 +394,10 @@ export const GetChallengeResponse: MessageFns<GetChallengeResponse> = {
|
|
|
350
394
|
break;
|
|
351
395
|
}
|
|
352
396
|
|
|
353
|
-
message.protectedChallenge = ProtectedChallenge.decode(
|
|
397
|
+
message.protectedChallenge = ProtectedChallenge.decode(
|
|
398
|
+
reader,
|
|
399
|
+
reader.uint32(),
|
|
400
|
+
);
|
|
354
401
|
continue;
|
|
355
402
|
}
|
|
356
403
|
}
|
|
@@ -373,7 +420,9 @@ export const GetChallengeResponse: MessageFns<GetChallengeResponse> = {
|
|
|
373
420
|
toJSON(message: GetChallengeResponse): unknown {
|
|
374
421
|
const obj: any = {};
|
|
375
422
|
if (message.protectedChallenge !== undefined) {
|
|
376
|
-
obj.protectedChallenge = ProtectedChallenge.toJSON(
|
|
423
|
+
obj.protectedChallenge = ProtectedChallenge.toJSON(
|
|
424
|
+
message.protectedChallenge,
|
|
425
|
+
);
|
|
377
426
|
}
|
|
378
427
|
return obj;
|
|
379
428
|
},
|
|
@@ -383,21 +432,33 @@ export const GetChallengeResponse: MessageFns<GetChallengeResponse> = {
|
|
|
383
432
|
},
|
|
384
433
|
fromPartial(object: DeepPartial<GetChallengeResponse>): GetChallengeResponse {
|
|
385
434
|
const message = createBaseGetChallengeResponse();
|
|
386
|
-
message.protectedChallenge =
|
|
387
|
-
|
|
388
|
-
|
|
435
|
+
message.protectedChallenge =
|
|
436
|
+
object.protectedChallenge !== undefined &&
|
|
437
|
+
object.protectedChallenge !== null
|
|
438
|
+
? ProtectedChallenge.fromPartial(object.protectedChallenge)
|
|
439
|
+
: undefined;
|
|
389
440
|
return message;
|
|
390
441
|
},
|
|
391
442
|
};
|
|
392
443
|
|
|
393
444
|
function createBaseVerifyChallengeRequest(): VerifyChallengeRequest {
|
|
394
|
-
return {
|
|
445
|
+
return {
|
|
446
|
+
protectedChallenge: undefined,
|
|
447
|
+
signature: new Uint8Array(0),
|
|
448
|
+
publicKey: new Uint8Array(0),
|
|
449
|
+
};
|
|
395
450
|
}
|
|
396
451
|
|
|
397
452
|
export const VerifyChallengeRequest: MessageFns<VerifyChallengeRequest> = {
|
|
398
|
-
encode(
|
|
453
|
+
encode(
|
|
454
|
+
message: VerifyChallengeRequest,
|
|
455
|
+
writer: BinaryWriter = new BinaryWriter(),
|
|
456
|
+
): BinaryWriter {
|
|
399
457
|
if (message.protectedChallenge !== undefined) {
|
|
400
|
-
ProtectedChallenge.encode(
|
|
458
|
+
ProtectedChallenge.encode(
|
|
459
|
+
message.protectedChallenge,
|
|
460
|
+
writer.uint32(10).fork(),
|
|
461
|
+
).join();
|
|
401
462
|
}
|
|
402
463
|
if (message.signature.length !== 0) {
|
|
403
464
|
writer.uint32(18).bytes(message.signature);
|
|
@@ -408,8 +469,12 @@ export const VerifyChallengeRequest: MessageFns<VerifyChallengeRequest> = {
|
|
|
408
469
|
return writer;
|
|
409
470
|
},
|
|
410
471
|
|
|
411
|
-
decode(
|
|
412
|
-
|
|
472
|
+
decode(
|
|
473
|
+
input: BinaryReader | Uint8Array,
|
|
474
|
+
length?: number,
|
|
475
|
+
): VerifyChallengeRequest {
|
|
476
|
+
const reader =
|
|
477
|
+
input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
413
478
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
414
479
|
const message = createBaseVerifyChallengeRequest();
|
|
415
480
|
while (reader.pos < end) {
|
|
@@ -420,7 +485,10 @@ export const VerifyChallengeRequest: MessageFns<VerifyChallengeRequest> = {
|
|
|
420
485
|
break;
|
|
421
486
|
}
|
|
422
487
|
|
|
423
|
-
message.protectedChallenge = ProtectedChallenge.decode(
|
|
488
|
+
message.protectedChallenge = ProtectedChallenge.decode(
|
|
489
|
+
reader,
|
|
490
|
+
reader.uint32(),
|
|
491
|
+
);
|
|
424
492
|
continue;
|
|
425
493
|
}
|
|
426
494
|
case 2: {
|
|
@@ -453,15 +521,21 @@ export const VerifyChallengeRequest: MessageFns<VerifyChallengeRequest> = {
|
|
|
453
521
|
protectedChallenge: isSet(object.protectedChallenge)
|
|
454
522
|
? ProtectedChallenge.fromJSON(object.protectedChallenge)
|
|
455
523
|
: undefined,
|
|
456
|
-
signature: isSet(object.signature)
|
|
457
|
-
|
|
524
|
+
signature: isSet(object.signature)
|
|
525
|
+
? bytesFromBase64(object.signature)
|
|
526
|
+
: new Uint8Array(0),
|
|
527
|
+
publicKey: isSet(object.publicKey)
|
|
528
|
+
? bytesFromBase64(object.publicKey)
|
|
529
|
+
: new Uint8Array(0),
|
|
458
530
|
};
|
|
459
531
|
},
|
|
460
532
|
|
|
461
533
|
toJSON(message: VerifyChallengeRequest): unknown {
|
|
462
534
|
const obj: any = {};
|
|
463
535
|
if (message.protectedChallenge !== undefined) {
|
|
464
|
-
obj.protectedChallenge = ProtectedChallenge.toJSON(
|
|
536
|
+
obj.protectedChallenge = ProtectedChallenge.toJSON(
|
|
537
|
+
message.protectedChallenge,
|
|
538
|
+
);
|
|
465
539
|
}
|
|
466
540
|
if (message.signature.length !== 0) {
|
|
467
541
|
obj.signature = base64FromBytes(message.signature);
|
|
@@ -475,11 +549,15 @@ export const VerifyChallengeRequest: MessageFns<VerifyChallengeRequest> = {
|
|
|
475
549
|
create(base?: DeepPartial<VerifyChallengeRequest>): VerifyChallengeRequest {
|
|
476
550
|
return VerifyChallengeRequest.fromPartial(base ?? {});
|
|
477
551
|
},
|
|
478
|
-
fromPartial(
|
|
552
|
+
fromPartial(
|
|
553
|
+
object: DeepPartial<VerifyChallengeRequest>,
|
|
554
|
+
): VerifyChallengeRequest {
|
|
479
555
|
const message = createBaseVerifyChallengeRequest();
|
|
480
|
-
message.protectedChallenge =
|
|
481
|
-
|
|
482
|
-
|
|
556
|
+
message.protectedChallenge =
|
|
557
|
+
object.protectedChallenge !== undefined &&
|
|
558
|
+
object.protectedChallenge !== null
|
|
559
|
+
? ProtectedChallenge.fromPartial(object.protectedChallenge)
|
|
560
|
+
: undefined;
|
|
483
561
|
message.signature = object.signature ?? new Uint8Array(0);
|
|
484
562
|
message.publicKey = object.publicKey ?? new Uint8Array(0);
|
|
485
563
|
return message;
|
|
@@ -491,7 +569,10 @@ function createBaseVerifyChallengeResponse(): VerifyChallengeResponse {
|
|
|
491
569
|
}
|
|
492
570
|
|
|
493
571
|
export const VerifyChallengeResponse: MessageFns<VerifyChallengeResponse> = {
|
|
494
|
-
encode(
|
|
572
|
+
encode(
|
|
573
|
+
message: VerifyChallengeResponse,
|
|
574
|
+
writer: BinaryWriter = new BinaryWriter(),
|
|
575
|
+
): BinaryWriter {
|
|
495
576
|
if (message.sessionToken !== "") {
|
|
496
577
|
writer.uint32(10).string(message.sessionToken);
|
|
497
578
|
}
|
|
@@ -501,8 +582,12 @@ export const VerifyChallengeResponse: MessageFns<VerifyChallengeResponse> = {
|
|
|
501
582
|
return writer;
|
|
502
583
|
},
|
|
503
584
|
|
|
504
|
-
decode(
|
|
505
|
-
|
|
585
|
+
decode(
|
|
586
|
+
input: BinaryReader | Uint8Array,
|
|
587
|
+
length?: number,
|
|
588
|
+
): VerifyChallengeResponse {
|
|
589
|
+
const reader =
|
|
590
|
+
input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
506
591
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
507
592
|
const message = createBaseVerifyChallengeResponse();
|
|
508
593
|
while (reader.pos < end) {
|
|
@@ -535,8 +620,12 @@ export const VerifyChallengeResponse: MessageFns<VerifyChallengeResponse> = {
|
|
|
535
620
|
|
|
536
621
|
fromJSON(object: any): VerifyChallengeResponse {
|
|
537
622
|
return {
|
|
538
|
-
sessionToken: isSet(object.sessionToken)
|
|
539
|
-
|
|
623
|
+
sessionToken: isSet(object.sessionToken)
|
|
624
|
+
? globalThis.String(object.sessionToken)
|
|
625
|
+
: "",
|
|
626
|
+
expirationTimestamp: isSet(object.expirationTimestamp)
|
|
627
|
+
? globalThis.Number(object.expirationTimestamp)
|
|
628
|
+
: 0,
|
|
540
629
|
};
|
|
541
630
|
},
|
|
542
631
|
|
|
@@ -554,7 +643,9 @@ export const VerifyChallengeResponse: MessageFns<VerifyChallengeResponse> = {
|
|
|
554
643
|
create(base?: DeepPartial<VerifyChallengeResponse>): VerifyChallengeResponse {
|
|
555
644
|
return VerifyChallengeResponse.fromPartial(base ?? {});
|
|
556
645
|
},
|
|
557
|
-
fromPartial(
|
|
646
|
+
fromPartial(
|
|
647
|
+
object: DeepPartial<VerifyChallengeResponse>,
|
|
648
|
+
): VerifyChallengeResponse {
|
|
558
649
|
const message = createBaseVerifyChallengeResponse();
|
|
559
650
|
message.sessionToken = object.sessionToken ?? "";
|
|
560
651
|
message.expirationTimestamp = object.expirationTimestamp ?? 0;
|
|
@@ -639,14 +730,28 @@ function base64FromBytes(arr: Uint8Array): string {
|
|
|
639
730
|
}
|
|
640
731
|
}
|
|
641
732
|
|
|
642
|
-
type Builtin =
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
733
|
+
type Builtin =
|
|
734
|
+
| Date
|
|
735
|
+
| Function
|
|
736
|
+
| Uint8Array
|
|
737
|
+
| string
|
|
738
|
+
| number
|
|
739
|
+
| boolean
|
|
740
|
+
| undefined;
|
|
741
|
+
|
|
742
|
+
export type DeepPartial<T> = T extends Builtin
|
|
743
|
+
? T
|
|
744
|
+
: T extends globalThis.Array<infer U>
|
|
745
|
+
? globalThis.Array<DeepPartial<U>>
|
|
746
|
+
: T extends ReadonlyArray<infer U>
|
|
747
|
+
? ReadonlyArray<DeepPartial<U>>
|
|
748
|
+
: T extends { $case: string }
|
|
749
|
+
? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & {
|
|
750
|
+
$case: T["$case"];
|
|
751
|
+
}
|
|
752
|
+
: T extends {}
|
|
753
|
+
? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
754
|
+
: Partial<T>;
|
|
650
755
|
|
|
651
756
|
function longToNumber(int64: { toString(): string }): number {
|
|
652
757
|
const num = globalThis.Number(int64.toString());
|