@buildonspark/spark-sdk 0.2.1 → 0.2.3
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/CHANGELOG.md +13 -0
- package/dist/{chunk-TM6CHQXC.js → chunk-3SEOTO43.js} +1 -1
- package/dist/{chunk-2ENZX6LT.js → chunk-AAZWSPUK.js} +84 -8
- package/dist/{chunk-4JD4HIAN.js → chunk-G4MSZ6DE.js} +299 -1
- package/dist/{chunk-KFDVDUIS.js → chunk-PLLJIZC3.js} +138 -35
- package/dist/{chunk-N4JAOOIN.js → chunk-PTRXJS7Q.js} +1 -1
- package/dist/{client-DKbwpcnl.d.ts → client-CGTRS23n.d.ts} +21 -4
- package/dist/{client-Drs5Lapg.d.cts → client-CcYzmpmj.d.cts} +21 -4
- package/dist/debug.cjs +455 -40
- package/dist/debug.d.cts +5 -5
- package/dist/debug.d.ts +5 -5
- package/dist/debug.js +4 -4
- package/dist/graphql/objects/index.d.cts +2 -2
- package/dist/graphql/objects/index.d.ts +2 -2
- package/dist/index.cjs +515 -40
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +7 -5
- package/dist/index.node.cjs +517 -44
- package/dist/index.node.d.cts +8 -6
- package/dist/index.node.d.ts +8 -6
- package/dist/index.node.js +6 -4
- package/dist/native/index.cjs +459 -43
- package/dist/native/index.d.cts +62 -15
- package/dist/native/index.d.ts +62 -15
- package/dist/native/index.js +459 -43
- package/dist/proto/lrc20.d.cts +1 -1
- package/dist/proto/lrc20.d.ts +1 -1
- package/dist/proto/lrc20.js +1 -1
- package/dist/proto/spark.cjs +84 -8
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/dist/proto/spark.js +1 -1
- package/dist/proto/spark_token.cjs +301 -0
- package/dist/proto/spark_token.d.cts +35 -2
- package/dist/proto/spark_token.d.ts +35 -2
- package/dist/proto/spark_token.js +8 -2
- package/dist/{sdk-types-DJ2ve9YY.d.cts → sdk-types-CB9HrW5O.d.cts} +1 -1
- package/dist/{sdk-types-DCIVdKUT.d.ts → sdk-types-CkRNraXT.d.ts} +1 -1
- package/dist/{spark-BUOx3U7Q.d.cts → spark-B_7nZx6T.d.cts} +112 -10
- package/dist/{spark-BUOx3U7Q.d.ts → spark-B_7nZx6T.d.ts} +112 -10
- package/dist/{spark-wallet-DbCjWOfP.d.ts → spark-wallet-CxcGPXRB.d.ts} +10 -6
- package/dist/{spark-wallet-BslnB-4H.d.cts → spark-wallet-DJJm19BP.d.cts} +10 -6
- package/dist/tests/test-utils.cjs +455 -17
- package/dist/tests/test-utils.d.cts +9 -5
- package/dist/tests/test-utils.d.ts +9 -5
- package/dist/tests/test-utils.js +13 -6
- package/dist/types/index.cjs +84 -8
- package/dist/types/index.d.cts +3 -3
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js +2 -2
- package/dist/{xchain-address-BIcYZU3K.d.ts → xchain-address-Bh9w1SeC.d.ts} +3 -3
- package/dist/{xchain-address-C3B-Jfk5.d.cts → xchain-address-SZ7dkVUE.d.cts} +3 -3
- package/package.json +1 -1
- package/src/index.node.ts +6 -6
- package/src/index.ts +5 -5
- package/src/proto/spark.ts +172 -16
- package/src/proto/spark_token.ts +369 -0
- package/src/services/connection.ts +3 -3
- package/src/services/coop-exit.ts +1 -1
- package/src/services/deposit.ts +2 -2
- package/src/services/signing.ts +1 -1
- package/src/services/token-transactions.ts +6 -2
- package/src/services/transfer.ts +25 -9
- package/src/services/tree-creation.ts +10 -7
- package/src/signer/signer.react-native.ts +4 -3
- package/src/signer/signer.ts +84 -6
- package/src/signer/types.ts +7 -1
- package/src/spark-wallet/spark-wallet.ts +56 -15
- package/src/tests/integration/coop-exit.test.ts +5 -3
- package/src/tests/integration/deposit.test.ts +20 -10
- package/src/tests/integration/lightning.test.ts +13 -7
- package/src/tests/integration/message-signing.test.ts +10 -7
- package/src/tests/integration/swap.test.ts +8 -4
- package/src/tests/integration/transfer.test.ts +25 -11
- package/src/tests/integration/wallet.test.ts +9 -4
- package/src/tests/test-utils.ts +10 -1
package/src/proto/spark_token.ts
CHANGED
|
@@ -344,6 +344,31 @@ export interface TokenTransactionWithStatus {
|
|
|
344
344
|
tokenTransactionHash: Uint8Array;
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
+
export interface FreezeTokensPayload {
|
|
348
|
+
version: number;
|
|
349
|
+
ownerPublicKey: Uint8Array;
|
|
350
|
+
tokenPublicKey?: Uint8Array | undefined;
|
|
351
|
+
tokenIdentifier?: Uint8Array | undefined;
|
|
352
|
+
issuerProvidedTimestamp: number;
|
|
353
|
+
operatorIdentityPublicKey: Uint8Array;
|
|
354
|
+
/** Set to false when requesting a freeze. */
|
|
355
|
+
shouldUnfreeze: boolean;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export interface FreezeTokensRequest {
|
|
359
|
+
freezeTokensPayload:
|
|
360
|
+
| FreezeTokensPayload
|
|
361
|
+
| undefined;
|
|
362
|
+
/** This is a Schnorr or ECDSA DER signature which can be between 64 and 73 bytes. */
|
|
363
|
+
issuerSignature: Uint8Array;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export interface FreezeTokensResponse {
|
|
367
|
+
impactedOutputIds: string[];
|
|
368
|
+
/** Decoded uint128 */
|
|
369
|
+
impactedTokenAmount: Uint8Array;
|
|
370
|
+
}
|
|
371
|
+
|
|
347
372
|
function createBaseTokenOutputToSpend(): TokenOutputToSpend {
|
|
348
373
|
return { prevTokenTransactionHash: new Uint8Array(0), prevTokenTransactionVout: 0 };
|
|
349
374
|
}
|
|
@@ -2803,6 +2828,334 @@ export const TokenTransactionWithStatus: MessageFns<TokenTransactionWithStatus>
|
|
|
2803
2828
|
},
|
|
2804
2829
|
};
|
|
2805
2830
|
|
|
2831
|
+
function createBaseFreezeTokensPayload(): FreezeTokensPayload {
|
|
2832
|
+
return {
|
|
2833
|
+
version: 0,
|
|
2834
|
+
ownerPublicKey: new Uint8Array(0),
|
|
2835
|
+
tokenPublicKey: undefined,
|
|
2836
|
+
tokenIdentifier: undefined,
|
|
2837
|
+
issuerProvidedTimestamp: 0,
|
|
2838
|
+
operatorIdentityPublicKey: new Uint8Array(0),
|
|
2839
|
+
shouldUnfreeze: false,
|
|
2840
|
+
};
|
|
2841
|
+
}
|
|
2842
|
+
|
|
2843
|
+
export const FreezeTokensPayload: MessageFns<FreezeTokensPayload> = {
|
|
2844
|
+
encode(message: FreezeTokensPayload, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
|
2845
|
+
if (message.version !== 0) {
|
|
2846
|
+
writer.uint32(8).uint32(message.version);
|
|
2847
|
+
}
|
|
2848
|
+
if (message.ownerPublicKey.length !== 0) {
|
|
2849
|
+
writer.uint32(18).bytes(message.ownerPublicKey);
|
|
2850
|
+
}
|
|
2851
|
+
if (message.tokenPublicKey !== undefined) {
|
|
2852
|
+
writer.uint32(26).bytes(message.tokenPublicKey);
|
|
2853
|
+
}
|
|
2854
|
+
if (message.tokenIdentifier !== undefined) {
|
|
2855
|
+
writer.uint32(34).bytes(message.tokenIdentifier);
|
|
2856
|
+
}
|
|
2857
|
+
if (message.issuerProvidedTimestamp !== 0) {
|
|
2858
|
+
writer.uint32(40).uint64(message.issuerProvidedTimestamp);
|
|
2859
|
+
}
|
|
2860
|
+
if (message.operatorIdentityPublicKey.length !== 0) {
|
|
2861
|
+
writer.uint32(50).bytes(message.operatorIdentityPublicKey);
|
|
2862
|
+
}
|
|
2863
|
+
if (message.shouldUnfreeze !== false) {
|
|
2864
|
+
writer.uint32(56).bool(message.shouldUnfreeze);
|
|
2865
|
+
}
|
|
2866
|
+
return writer;
|
|
2867
|
+
},
|
|
2868
|
+
|
|
2869
|
+
decode(input: BinaryReader | Uint8Array, length?: number): FreezeTokensPayload {
|
|
2870
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
2871
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
2872
|
+
const message = createBaseFreezeTokensPayload();
|
|
2873
|
+
while (reader.pos < end) {
|
|
2874
|
+
const tag = reader.uint32();
|
|
2875
|
+
switch (tag >>> 3) {
|
|
2876
|
+
case 1: {
|
|
2877
|
+
if (tag !== 8) {
|
|
2878
|
+
break;
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
message.version = reader.uint32();
|
|
2882
|
+
continue;
|
|
2883
|
+
}
|
|
2884
|
+
case 2: {
|
|
2885
|
+
if (tag !== 18) {
|
|
2886
|
+
break;
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
message.ownerPublicKey = reader.bytes();
|
|
2890
|
+
continue;
|
|
2891
|
+
}
|
|
2892
|
+
case 3: {
|
|
2893
|
+
if (tag !== 26) {
|
|
2894
|
+
break;
|
|
2895
|
+
}
|
|
2896
|
+
|
|
2897
|
+
message.tokenPublicKey = reader.bytes();
|
|
2898
|
+
continue;
|
|
2899
|
+
}
|
|
2900
|
+
case 4: {
|
|
2901
|
+
if (tag !== 34) {
|
|
2902
|
+
break;
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2905
|
+
message.tokenIdentifier = reader.bytes();
|
|
2906
|
+
continue;
|
|
2907
|
+
}
|
|
2908
|
+
case 5: {
|
|
2909
|
+
if (tag !== 40) {
|
|
2910
|
+
break;
|
|
2911
|
+
}
|
|
2912
|
+
|
|
2913
|
+
message.issuerProvidedTimestamp = longToNumber(reader.uint64());
|
|
2914
|
+
continue;
|
|
2915
|
+
}
|
|
2916
|
+
case 6: {
|
|
2917
|
+
if (tag !== 50) {
|
|
2918
|
+
break;
|
|
2919
|
+
}
|
|
2920
|
+
|
|
2921
|
+
message.operatorIdentityPublicKey = reader.bytes();
|
|
2922
|
+
continue;
|
|
2923
|
+
}
|
|
2924
|
+
case 7: {
|
|
2925
|
+
if (tag !== 56) {
|
|
2926
|
+
break;
|
|
2927
|
+
}
|
|
2928
|
+
|
|
2929
|
+
message.shouldUnfreeze = reader.bool();
|
|
2930
|
+
continue;
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
2934
|
+
break;
|
|
2935
|
+
}
|
|
2936
|
+
reader.skip(tag & 7);
|
|
2937
|
+
}
|
|
2938
|
+
return message;
|
|
2939
|
+
},
|
|
2940
|
+
|
|
2941
|
+
fromJSON(object: any): FreezeTokensPayload {
|
|
2942
|
+
return {
|
|
2943
|
+
version: isSet(object.version) ? globalThis.Number(object.version) : 0,
|
|
2944
|
+
ownerPublicKey: isSet(object.ownerPublicKey) ? bytesFromBase64(object.ownerPublicKey) : new Uint8Array(0),
|
|
2945
|
+
tokenPublicKey: isSet(object.tokenPublicKey) ? bytesFromBase64(object.tokenPublicKey) : undefined,
|
|
2946
|
+
tokenIdentifier: isSet(object.tokenIdentifier) ? bytesFromBase64(object.tokenIdentifier) : undefined,
|
|
2947
|
+
issuerProvidedTimestamp: isSet(object.issuerProvidedTimestamp)
|
|
2948
|
+
? globalThis.Number(object.issuerProvidedTimestamp)
|
|
2949
|
+
: 0,
|
|
2950
|
+
operatorIdentityPublicKey: isSet(object.operatorIdentityPublicKey)
|
|
2951
|
+
? bytesFromBase64(object.operatorIdentityPublicKey)
|
|
2952
|
+
: new Uint8Array(0),
|
|
2953
|
+
shouldUnfreeze: isSet(object.shouldUnfreeze) ? globalThis.Boolean(object.shouldUnfreeze) : false,
|
|
2954
|
+
};
|
|
2955
|
+
},
|
|
2956
|
+
|
|
2957
|
+
toJSON(message: FreezeTokensPayload): unknown {
|
|
2958
|
+
const obj: any = {};
|
|
2959
|
+
if (message.version !== 0) {
|
|
2960
|
+
obj.version = Math.round(message.version);
|
|
2961
|
+
}
|
|
2962
|
+
if (message.ownerPublicKey.length !== 0) {
|
|
2963
|
+
obj.ownerPublicKey = base64FromBytes(message.ownerPublicKey);
|
|
2964
|
+
}
|
|
2965
|
+
if (message.tokenPublicKey !== undefined) {
|
|
2966
|
+
obj.tokenPublicKey = base64FromBytes(message.tokenPublicKey);
|
|
2967
|
+
}
|
|
2968
|
+
if (message.tokenIdentifier !== undefined) {
|
|
2969
|
+
obj.tokenIdentifier = base64FromBytes(message.tokenIdentifier);
|
|
2970
|
+
}
|
|
2971
|
+
if (message.issuerProvidedTimestamp !== 0) {
|
|
2972
|
+
obj.issuerProvidedTimestamp = Math.round(message.issuerProvidedTimestamp);
|
|
2973
|
+
}
|
|
2974
|
+
if (message.operatorIdentityPublicKey.length !== 0) {
|
|
2975
|
+
obj.operatorIdentityPublicKey = base64FromBytes(message.operatorIdentityPublicKey);
|
|
2976
|
+
}
|
|
2977
|
+
if (message.shouldUnfreeze !== false) {
|
|
2978
|
+
obj.shouldUnfreeze = message.shouldUnfreeze;
|
|
2979
|
+
}
|
|
2980
|
+
return obj;
|
|
2981
|
+
},
|
|
2982
|
+
|
|
2983
|
+
create(base?: DeepPartial<FreezeTokensPayload>): FreezeTokensPayload {
|
|
2984
|
+
return FreezeTokensPayload.fromPartial(base ?? {});
|
|
2985
|
+
},
|
|
2986
|
+
fromPartial(object: DeepPartial<FreezeTokensPayload>): FreezeTokensPayload {
|
|
2987
|
+
const message = createBaseFreezeTokensPayload();
|
|
2988
|
+
message.version = object.version ?? 0;
|
|
2989
|
+
message.ownerPublicKey = object.ownerPublicKey ?? new Uint8Array(0);
|
|
2990
|
+
message.tokenPublicKey = object.tokenPublicKey ?? undefined;
|
|
2991
|
+
message.tokenIdentifier = object.tokenIdentifier ?? undefined;
|
|
2992
|
+
message.issuerProvidedTimestamp = object.issuerProvidedTimestamp ?? 0;
|
|
2993
|
+
message.operatorIdentityPublicKey = object.operatorIdentityPublicKey ?? new Uint8Array(0);
|
|
2994
|
+
message.shouldUnfreeze = object.shouldUnfreeze ?? false;
|
|
2995
|
+
return message;
|
|
2996
|
+
},
|
|
2997
|
+
};
|
|
2998
|
+
|
|
2999
|
+
function createBaseFreezeTokensRequest(): FreezeTokensRequest {
|
|
3000
|
+
return { freezeTokensPayload: undefined, issuerSignature: new Uint8Array(0) };
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
export const FreezeTokensRequest: MessageFns<FreezeTokensRequest> = {
|
|
3004
|
+
encode(message: FreezeTokensRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
|
3005
|
+
if (message.freezeTokensPayload !== undefined) {
|
|
3006
|
+
FreezeTokensPayload.encode(message.freezeTokensPayload, writer.uint32(10).fork()).join();
|
|
3007
|
+
}
|
|
3008
|
+
if (message.issuerSignature.length !== 0) {
|
|
3009
|
+
writer.uint32(18).bytes(message.issuerSignature);
|
|
3010
|
+
}
|
|
3011
|
+
return writer;
|
|
3012
|
+
},
|
|
3013
|
+
|
|
3014
|
+
decode(input: BinaryReader | Uint8Array, length?: number): FreezeTokensRequest {
|
|
3015
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
3016
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
3017
|
+
const message = createBaseFreezeTokensRequest();
|
|
3018
|
+
while (reader.pos < end) {
|
|
3019
|
+
const tag = reader.uint32();
|
|
3020
|
+
switch (tag >>> 3) {
|
|
3021
|
+
case 1: {
|
|
3022
|
+
if (tag !== 10) {
|
|
3023
|
+
break;
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
message.freezeTokensPayload = FreezeTokensPayload.decode(reader, reader.uint32());
|
|
3027
|
+
continue;
|
|
3028
|
+
}
|
|
3029
|
+
case 2: {
|
|
3030
|
+
if (tag !== 18) {
|
|
3031
|
+
break;
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
message.issuerSignature = reader.bytes();
|
|
3035
|
+
continue;
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
3039
|
+
break;
|
|
3040
|
+
}
|
|
3041
|
+
reader.skip(tag & 7);
|
|
3042
|
+
}
|
|
3043
|
+
return message;
|
|
3044
|
+
},
|
|
3045
|
+
|
|
3046
|
+
fromJSON(object: any): FreezeTokensRequest {
|
|
3047
|
+
return {
|
|
3048
|
+
freezeTokensPayload: isSet(object.freezeTokensPayload)
|
|
3049
|
+
? FreezeTokensPayload.fromJSON(object.freezeTokensPayload)
|
|
3050
|
+
: undefined,
|
|
3051
|
+
issuerSignature: isSet(object.issuerSignature) ? bytesFromBase64(object.issuerSignature) : new Uint8Array(0),
|
|
3052
|
+
};
|
|
3053
|
+
},
|
|
3054
|
+
|
|
3055
|
+
toJSON(message: FreezeTokensRequest): unknown {
|
|
3056
|
+
const obj: any = {};
|
|
3057
|
+
if (message.freezeTokensPayload !== undefined) {
|
|
3058
|
+
obj.freezeTokensPayload = FreezeTokensPayload.toJSON(message.freezeTokensPayload);
|
|
3059
|
+
}
|
|
3060
|
+
if (message.issuerSignature.length !== 0) {
|
|
3061
|
+
obj.issuerSignature = base64FromBytes(message.issuerSignature);
|
|
3062
|
+
}
|
|
3063
|
+
return obj;
|
|
3064
|
+
},
|
|
3065
|
+
|
|
3066
|
+
create(base?: DeepPartial<FreezeTokensRequest>): FreezeTokensRequest {
|
|
3067
|
+
return FreezeTokensRequest.fromPartial(base ?? {});
|
|
3068
|
+
},
|
|
3069
|
+
fromPartial(object: DeepPartial<FreezeTokensRequest>): FreezeTokensRequest {
|
|
3070
|
+
const message = createBaseFreezeTokensRequest();
|
|
3071
|
+
message.freezeTokensPayload = (object.freezeTokensPayload !== undefined && object.freezeTokensPayload !== null)
|
|
3072
|
+
? FreezeTokensPayload.fromPartial(object.freezeTokensPayload)
|
|
3073
|
+
: undefined;
|
|
3074
|
+
message.issuerSignature = object.issuerSignature ?? new Uint8Array(0);
|
|
3075
|
+
return message;
|
|
3076
|
+
},
|
|
3077
|
+
};
|
|
3078
|
+
|
|
3079
|
+
function createBaseFreezeTokensResponse(): FreezeTokensResponse {
|
|
3080
|
+
return { impactedOutputIds: [], impactedTokenAmount: new Uint8Array(0) };
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
export const FreezeTokensResponse: MessageFns<FreezeTokensResponse> = {
|
|
3084
|
+
encode(message: FreezeTokensResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
|
|
3085
|
+
for (const v of message.impactedOutputIds) {
|
|
3086
|
+
writer.uint32(10).string(v!);
|
|
3087
|
+
}
|
|
3088
|
+
if (message.impactedTokenAmount.length !== 0) {
|
|
3089
|
+
writer.uint32(18).bytes(message.impactedTokenAmount);
|
|
3090
|
+
}
|
|
3091
|
+
return writer;
|
|
3092
|
+
},
|
|
3093
|
+
|
|
3094
|
+
decode(input: BinaryReader | Uint8Array, length?: number): FreezeTokensResponse {
|
|
3095
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
3096
|
+
const end = length === undefined ? reader.len : reader.pos + length;
|
|
3097
|
+
const message = createBaseFreezeTokensResponse();
|
|
3098
|
+
while (reader.pos < end) {
|
|
3099
|
+
const tag = reader.uint32();
|
|
3100
|
+
switch (tag >>> 3) {
|
|
3101
|
+
case 1: {
|
|
3102
|
+
if (tag !== 10) {
|
|
3103
|
+
break;
|
|
3104
|
+
}
|
|
3105
|
+
|
|
3106
|
+
message.impactedOutputIds.push(reader.string());
|
|
3107
|
+
continue;
|
|
3108
|
+
}
|
|
3109
|
+
case 2: {
|
|
3110
|
+
if (tag !== 18) {
|
|
3111
|
+
break;
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3114
|
+
message.impactedTokenAmount = reader.bytes();
|
|
3115
|
+
continue;
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
3119
|
+
break;
|
|
3120
|
+
}
|
|
3121
|
+
reader.skip(tag & 7);
|
|
3122
|
+
}
|
|
3123
|
+
return message;
|
|
3124
|
+
},
|
|
3125
|
+
|
|
3126
|
+
fromJSON(object: any): FreezeTokensResponse {
|
|
3127
|
+
return {
|
|
3128
|
+
impactedOutputIds: globalThis.Array.isArray(object?.impactedOutputIds)
|
|
3129
|
+
? object.impactedOutputIds.map((e: any) => globalThis.String(e))
|
|
3130
|
+
: [],
|
|
3131
|
+
impactedTokenAmount: isSet(object.impactedTokenAmount)
|
|
3132
|
+
? bytesFromBase64(object.impactedTokenAmount)
|
|
3133
|
+
: new Uint8Array(0),
|
|
3134
|
+
};
|
|
3135
|
+
},
|
|
3136
|
+
|
|
3137
|
+
toJSON(message: FreezeTokensResponse): unknown {
|
|
3138
|
+
const obj: any = {};
|
|
3139
|
+
if (message.impactedOutputIds?.length) {
|
|
3140
|
+
obj.impactedOutputIds = message.impactedOutputIds;
|
|
3141
|
+
}
|
|
3142
|
+
if (message.impactedTokenAmount.length !== 0) {
|
|
3143
|
+
obj.impactedTokenAmount = base64FromBytes(message.impactedTokenAmount);
|
|
3144
|
+
}
|
|
3145
|
+
return obj;
|
|
3146
|
+
},
|
|
3147
|
+
|
|
3148
|
+
create(base?: DeepPartial<FreezeTokensResponse>): FreezeTokensResponse {
|
|
3149
|
+
return FreezeTokensResponse.fromPartial(base ?? {});
|
|
3150
|
+
},
|
|
3151
|
+
fromPartial(object: DeepPartial<FreezeTokensResponse>): FreezeTokensResponse {
|
|
3152
|
+
const message = createBaseFreezeTokensResponse();
|
|
3153
|
+
message.impactedOutputIds = object.impactedOutputIds?.map((e) => e) || [];
|
|
3154
|
+
message.impactedTokenAmount = object.impactedTokenAmount ?? new Uint8Array(0);
|
|
3155
|
+
return message;
|
|
3156
|
+
},
|
|
3157
|
+
};
|
|
3158
|
+
|
|
2806
3159
|
export type SparkTokenServiceDefinition = typeof SparkTokenServiceDefinition;
|
|
2807
3160
|
export const SparkTokenServiceDefinition = {
|
|
2808
3161
|
name: "SparkTokenService",
|
|
@@ -2856,6 +3209,14 @@ export const SparkTokenServiceDefinition = {
|
|
|
2856
3209
|
responseStream: false,
|
|
2857
3210
|
options: {},
|
|
2858
3211
|
},
|
|
3212
|
+
freeze_tokens: {
|
|
3213
|
+
name: "freeze_tokens",
|
|
3214
|
+
requestType: FreezeTokensRequest,
|
|
3215
|
+
requestStream: false,
|
|
3216
|
+
responseType: FreezeTokensResponse,
|
|
3217
|
+
responseStream: false,
|
|
3218
|
+
options: {},
|
|
3219
|
+
},
|
|
2859
3220
|
},
|
|
2860
3221
|
} as const;
|
|
2861
3222
|
|
|
@@ -2888,6 +3249,10 @@ export interface SparkTokenServiceImplementation<CallContextExt = {}> {
|
|
|
2888
3249
|
request: QueryTokenOutputsRequest,
|
|
2889
3250
|
context: CallContext & CallContextExt,
|
|
2890
3251
|
): Promise<DeepPartial<QueryTokenOutputsResponse>>;
|
|
3252
|
+
freeze_tokens(
|
|
3253
|
+
request: FreezeTokensRequest,
|
|
3254
|
+
context: CallContext & CallContextExt,
|
|
3255
|
+
): Promise<DeepPartial<FreezeTokensResponse>>;
|
|
2891
3256
|
}
|
|
2892
3257
|
|
|
2893
3258
|
export interface SparkTokenServiceClient<CallOptionsExt = {}> {
|
|
@@ -2919,6 +3284,10 @@ export interface SparkTokenServiceClient<CallOptionsExt = {}> {
|
|
|
2919
3284
|
request: DeepPartial<QueryTokenOutputsRequest>,
|
|
2920
3285
|
options?: CallOptions & CallOptionsExt,
|
|
2921
3286
|
): Promise<QueryTokenOutputsResponse>;
|
|
3287
|
+
freeze_tokens(
|
|
3288
|
+
request: DeepPartial<FreezeTokensRequest>,
|
|
3289
|
+
options?: CallOptions & CallOptionsExt,
|
|
3290
|
+
): Promise<FreezeTokensResponse>;
|
|
2922
3291
|
}
|
|
2923
3292
|
|
|
2924
3293
|
function bytesFromBase64(b64: string): Uint8Array {
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
Channel as ChannelWeb,
|
|
8
8
|
ClientFactory as ClientFactoryWeb,
|
|
9
9
|
} from "nice-grpc-web";
|
|
10
|
-
import { isBun, isReactNative
|
|
10
|
+
import { clientEnv, isBun, isReactNative } from "../constants.js";
|
|
11
11
|
import { AuthenticationError, NetworkError } from "../errors/types.js";
|
|
12
12
|
import { MockServiceClient, MockServiceDefinition } from "../proto/mock.js";
|
|
13
13
|
import { SparkServiceClient, SparkServiceDefinition } from "../proto/spark.js";
|
|
@@ -16,12 +16,12 @@ import {
|
|
|
16
16
|
SparkAuthnServiceClient,
|
|
17
17
|
SparkAuthnServiceDefinition,
|
|
18
18
|
} from "../proto/spark_authn.js";
|
|
19
|
-
import { RetryOptions, SparkCallOptions } from "../types/grpc.js";
|
|
20
|
-
import { WalletConfigService } from "./config.js";
|
|
21
19
|
import {
|
|
22
20
|
SparkTokenServiceClient,
|
|
23
21
|
SparkTokenServiceDefinition,
|
|
24
22
|
} from "../proto/spark_token.js";
|
|
23
|
+
import { RetryOptions, SparkCallOptions } from "../types/grpc.js";
|
|
24
|
+
import { WalletConfigService } from "./config.js";
|
|
25
25
|
|
|
26
26
|
type SparkAuthnServiceClientWithClose = SparkAuthnServiceClient & {
|
|
27
27
|
close?: () => void;
|
|
@@ -157,7 +157,7 @@ export class CoopExitService extends BaseTransferService {
|
|
|
157
157
|
leaf.keyDerivation,
|
|
158
158
|
),
|
|
159
159
|
rawTx: refundTx.toBytes(),
|
|
160
|
-
signingNonceCommitment: signingNonceCommitment,
|
|
160
|
+
signingNonceCommitment: signingNonceCommitment.commitment,
|
|
161
161
|
},
|
|
162
162
|
// TODO: Add direct refund signature
|
|
163
163
|
directRefundTxSigningJob: undefined,
|
package/src/services/deposit.ts
CHANGED
|
@@ -280,12 +280,12 @@ export class DepositService {
|
|
|
280
280
|
rootTxSigningJob: {
|
|
281
281
|
rawTx: rootTx.toBytes(),
|
|
282
282
|
signingPublicKey: signingPubKey,
|
|
283
|
-
signingNonceCommitment: rootNonceCommitment,
|
|
283
|
+
signingNonceCommitment: rootNonceCommitment.commitment,
|
|
284
284
|
},
|
|
285
285
|
refundTxSigningJob: {
|
|
286
286
|
rawTx: refundTx.toBytes(),
|
|
287
287
|
signingPublicKey: signingPubKey,
|
|
288
|
-
signingNonceCommitment: refundNonceCommitment,
|
|
288
|
+
signingNonceCommitment: refundNonceCommitment.commitment,
|
|
289
289
|
},
|
|
290
290
|
});
|
|
291
291
|
} catch (error) {
|
package/src/services/signing.ts
CHANGED
|
@@ -99,7 +99,7 @@ export class SigningService {
|
|
|
99
99
|
leaf.keyDerivation,
|
|
100
100
|
),
|
|
101
101
|
rawTx: refundTx.toBytes(),
|
|
102
|
-
signingNonceCommitment: signingCommitment,
|
|
102
|
+
signingNonceCommitment: signingCommitment.commitment,
|
|
103
103
|
userSignature: signingResult,
|
|
104
104
|
signingCommitments: {
|
|
105
105
|
signingCommitments: signingNonceCommitments,
|
|
@@ -71,6 +71,8 @@ export interface QueryTokenTransactionsParams {
|
|
|
71
71
|
tokenTransactionHashes?: string[];
|
|
72
72
|
tokenIdentifiers?: string[];
|
|
73
73
|
outputIds?: string[];
|
|
74
|
+
pageSize: number;
|
|
75
|
+
offset: number;
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
export class TokenTransactionService {
|
|
@@ -1107,6 +1109,8 @@ export class TokenTransactionService {
|
|
|
1107
1109
|
tokenTransactionHashes,
|
|
1108
1110
|
tokenIdentifiers,
|
|
1109
1111
|
outputIds,
|
|
1112
|
+
pageSize,
|
|
1113
|
+
offset,
|
|
1110
1114
|
} = params;
|
|
1111
1115
|
|
|
1112
1116
|
const tokenClient = await this.connectionManager.createSparkTokenClient(
|
|
@@ -1119,8 +1123,8 @@ export class TokenTransactionService {
|
|
|
1119
1123
|
tokenIdentifiers: tokenIdentifiers?.map(hexToBytes)!,
|
|
1120
1124
|
tokenTransactionHashes: tokenTransactionHashes?.map(hexToBytes)!,
|
|
1121
1125
|
outputIds: outputIds || [],
|
|
1122
|
-
limit:
|
|
1123
|
-
offset:
|
|
1126
|
+
limit: pageSize,
|
|
1127
|
+
offset: offset,
|
|
1124
1128
|
};
|
|
1125
1129
|
|
|
1126
1130
|
try {
|
package/src/services/transfer.ts
CHANGED
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
import {
|
|
40
40
|
KeyDerivation,
|
|
41
41
|
KeyDerivationType,
|
|
42
|
-
|
|
42
|
+
SigningCommitmentWithOptionalNonce,
|
|
43
43
|
} from "../signer/types.js";
|
|
44
44
|
import {
|
|
45
45
|
getSigHashFromTx,
|
|
@@ -77,7 +77,7 @@ export type ClaimLeafData = {
|
|
|
77
77
|
keyDerivation: KeyDerivation;
|
|
78
78
|
tx?: Transaction;
|
|
79
79
|
refundTx?: Transaction;
|
|
80
|
-
signingNonceCommitment:
|
|
80
|
+
signingNonceCommitment: SigningCommitmentWithOptionalNonce;
|
|
81
81
|
vout?: number;
|
|
82
82
|
};
|
|
83
83
|
|
|
@@ -86,10 +86,26 @@ export type LeafRefundSigningData = {
|
|
|
86
86
|
receivingPubkey: Uint8Array;
|
|
87
87
|
tx: Transaction;
|
|
88
88
|
refundTx?: Transaction;
|
|
89
|
-
signingNonceCommitment:
|
|
89
|
+
signingNonceCommitment: SigningCommitmentWithOptionalNonce;
|
|
90
90
|
vout: number;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
+
export type SigningJobWithOptionalNonce = {
|
|
94
|
+
signingPublicKey: Uint8Array;
|
|
95
|
+
rawTx: Uint8Array;
|
|
96
|
+
signingNonceCommitment: SigningCommitmentWithOptionalNonce;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
function getSigningJobProto(
|
|
100
|
+
signingJob: SigningJobWithOptionalNonce,
|
|
101
|
+
): SigningJob {
|
|
102
|
+
return {
|
|
103
|
+
signingPublicKey: signingJob.signingPublicKey,
|
|
104
|
+
rawTx: signingJob.rawTx,
|
|
105
|
+
signingNonceCommitment: signingJob.signingNonceCommitment.commitment,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
export class BaseTransferService {
|
|
94
110
|
protected readonly config: WalletConfigService;
|
|
95
111
|
protected readonly connectionManager: ConnectionManager;
|
|
@@ -943,7 +959,7 @@ export class TransferService extends BaseTransferService {
|
|
|
943
959
|
refundSigningData.keyDerivation,
|
|
944
960
|
),
|
|
945
961
|
rawTx: refundTx.toBytes(),
|
|
946
|
-
signingNonceCommitment: refundNonceCommitmentProto,
|
|
962
|
+
signingNonceCommitment: refundNonceCommitmentProto.commitment,
|
|
947
963
|
},
|
|
948
964
|
// TODO: Add direct refund signature
|
|
949
965
|
directRefundTxSigningJob: undefined,
|
|
@@ -1212,7 +1228,7 @@ export class TransferService extends BaseTransferService {
|
|
|
1212
1228
|
throw Error("no nodes to refresh");
|
|
1213
1229
|
}
|
|
1214
1230
|
|
|
1215
|
-
const signingJobs:
|
|
1231
|
+
const signingJobs: SigningJobWithOptionalNonce[] = [];
|
|
1216
1232
|
const newNodeTxs: Transaction[] = [];
|
|
1217
1233
|
|
|
1218
1234
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -1337,7 +1353,7 @@ export class TransferService extends BaseTransferService {
|
|
|
1337
1353
|
const response = await sparkClient.refresh_timelock({
|
|
1338
1354
|
leafId: leaf.id,
|
|
1339
1355
|
ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
1340
|
-
signingJobs,
|
|
1356
|
+
signingJobs: signingJobs.map(getSigningJobProto),
|
|
1341
1357
|
});
|
|
1342
1358
|
|
|
1343
1359
|
if (signingJobs.length !== response.signingResults.length) {
|
|
@@ -1540,8 +1556,8 @@ export class TransferService extends BaseTransferService {
|
|
|
1540
1556
|
const response = await sparkClient.extend_leaf({
|
|
1541
1557
|
leafId: node.id,
|
|
1542
1558
|
ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
1543
|
-
nodeTxSigningJob: newNodeSigningJob,
|
|
1544
|
-
refundTxSigningJob: newRefundSigningJob,
|
|
1559
|
+
nodeTxSigningJob: getSigningJobProto(newNodeSigningJob),
|
|
1560
|
+
refundTxSigningJob: getSigningJobProto(newRefundSigningJob),
|
|
1545
1561
|
});
|
|
1546
1562
|
|
|
1547
1563
|
if (!response.nodeTxSigningResult || !response.refundTxSigningResult) {
|
|
@@ -1678,7 +1694,7 @@ export class TransferService extends BaseTransferService {
|
|
|
1678
1694
|
const response = await sparkClient.refresh_timelock({
|
|
1679
1695
|
leafId: node.id,
|
|
1680
1696
|
ownerIdentityPublicKey: await this.config.signer.getIdentityPublicKey(),
|
|
1681
|
-
signingJobs: [refundSigningJob],
|
|
1697
|
+
signingJobs: [getSigningJobProto(refundSigningJob)],
|
|
1682
1698
|
});
|
|
1683
1699
|
|
|
1684
1700
|
if (response.signingResults.length !== 1) {
|
|
@@ -15,7 +15,10 @@ import {
|
|
|
15
15
|
SigningJob,
|
|
16
16
|
TreeNode,
|
|
17
17
|
} from "../proto/spark.js";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
KeyDerivationType,
|
|
20
|
+
SigningCommitmentWithOptionalNonce,
|
|
21
|
+
} from "../signer/types.js";
|
|
19
22
|
import {
|
|
20
23
|
getP2TRAddressFromPublicKey,
|
|
21
24
|
getSigHashFromTx,
|
|
@@ -38,8 +41,8 @@ export type DepositAddressTree = {
|
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
export type CreationNodeWithNonces = CreationNode & {
|
|
41
|
-
nodeTxSigningCommitment?:
|
|
42
|
-
refundTxSigningCommitment?:
|
|
44
|
+
nodeTxSigningCommitment?: SigningCommitmentWithOptionalNonce | undefined;
|
|
45
|
+
refundTxSigningCommitment?: SigningCommitmentWithOptionalNonce | undefined;
|
|
43
46
|
};
|
|
44
47
|
|
|
45
48
|
const INITIAL_TIME_LOCK = 2000;
|
|
@@ -345,7 +348,7 @@ export class TreeCreationService {
|
|
|
345
348
|
const signingJob: SigningJob = {
|
|
346
349
|
signingPublicKey: node.signingPublicKey,
|
|
347
350
|
rawTx: tx.toBytes(),
|
|
348
|
-
signingNonceCommitment: signingNonceCommitment,
|
|
351
|
+
signingNonceCommitment: signingNonceCommitment.commitment,
|
|
349
352
|
};
|
|
350
353
|
|
|
351
354
|
internalCreationNode.nodeTxSigningCommitment = signingNonceCommitment;
|
|
@@ -382,7 +385,7 @@ export class TreeCreationService {
|
|
|
382
385
|
const childSigningJob: SigningJob = {
|
|
383
386
|
signingPublicKey: node.signingPublicKey,
|
|
384
387
|
rawTx: childTx.toBytes(),
|
|
385
|
-
signingNonceCommitment: childSigningNonceCommitment,
|
|
388
|
+
signingNonceCommitment: childSigningNonceCommitment.commitment,
|
|
386
389
|
};
|
|
387
390
|
|
|
388
391
|
childCreationNode.nodeTxSigningCommitment = childSigningNonceCommitment;
|
|
@@ -416,7 +419,7 @@ export class TreeCreationService {
|
|
|
416
419
|
const refundSigningJob: SigningJob = {
|
|
417
420
|
signingPublicKey: node.signingPublicKey,
|
|
418
421
|
rawTx: refundTx.toBytes(),
|
|
419
|
-
signingNonceCommitment: refundSigningNonceCommitment,
|
|
422
|
+
signingNonceCommitment: refundSigningNonceCommitment.commitment,
|
|
420
423
|
};
|
|
421
424
|
childCreationNode.refundTxSigningCommitment = refundSigningNonceCommitment;
|
|
422
425
|
childCreationNode.refundTxSigningJob = refundSigningJob;
|
|
@@ -466,7 +469,7 @@ export class TreeCreationService {
|
|
|
466
469
|
const rootNodeSigningJob: SigningJob = {
|
|
467
470
|
signingPublicKey: root.signingPublicKey,
|
|
468
471
|
rawTx: rootNodeTx.toBytes(),
|
|
469
|
-
signingNonceCommitment: rootNodeSigningCommitment,
|
|
472
|
+
signingNonceCommitment: rootNodeSigningCommitment.commitment,
|
|
470
473
|
};
|
|
471
474
|
const rootCreationNode: CreationNodeWithNonces = {
|
|
472
475
|
nodeTxSigningJob: rootNodeSigningJob,
|
|
@@ -23,7 +23,8 @@ export class ReactNativeSparkSigner extends DefaultSparkSigner {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const commitment = selfCommitment.commitment;
|
|
27
|
+
const nonce = this.commitmentToNonceMap.get(commitment);
|
|
27
28
|
if (!nonce) {
|
|
28
29
|
throw new ValidationError("Nonce not found for commitment", {
|
|
29
30
|
field: "nonce",
|
|
@@ -40,7 +41,7 @@ export class ReactNativeSparkSigner extends DefaultSparkSigner {
|
|
|
40
41
|
message,
|
|
41
42
|
keyPackage,
|
|
42
43
|
nonce,
|
|
43
|
-
selfCommitment,
|
|
44
|
+
selfCommitment: commitment,
|
|
44
45
|
statechainCommitments,
|
|
45
46
|
adaptorPubKey,
|
|
46
47
|
});
|
|
@@ -63,7 +64,7 @@ export class ReactNativeSparkSigner extends DefaultSparkSigner {
|
|
|
63
64
|
statechainPublicKeys,
|
|
64
65
|
verifyingKey,
|
|
65
66
|
statechainCommitments,
|
|
66
|
-
selfCommitment,
|
|
67
|
+
selfCommitment: selfCommitment.commitment,
|
|
67
68
|
selfPublicKey: publicKey,
|
|
68
69
|
selfSignature,
|
|
69
70
|
adaptorPubKey,
|