From 3c442d843335497fac90042442370747d39634d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Su=C3=A1rez?= Date: Tue, 20 Jan 2026 13:44:36 -0500 Subject: [PATCH 1/4] feat: remove deprecated methods related to allow spend and token locks --- packages/dag4-network/src/api/v2/l1-api.ts | 48 ---- packages/dag4-wallet/src/dag-account.ts | 218 +----------------- packages/dag4-wallet/src/validationSchemas.ts | 16 -- 3 files changed, 1 insertion(+), 281 deletions(-) diff --git a/packages/dag4-network/src/api/v2/l1-api.ts b/packages/dag4-network/src/api/v2/l1-api.ts index 3b8cd78..76beef1 100644 --- a/packages/dag4-network/src/api/v2/l1-api.ts +++ b/packages/dag4-network/src/api/v2/l1-api.ts @@ -36,54 +36,6 @@ class L1Api { ); } - /** - * @deprecated Use getAllowSpendLastRef() instead. This method will be removed in the next major version. - */ - async getAllowSpendLastRefDeprecated(l1Url: string, address: string) { - const l1Service = new RestApi(l1Url); - return l1Service.$get( - `/allow-spends/last-reference/${address}` - ); - } - - /** - * @deprecated Use postAllowSpend() instead. This method will be removed in the next major version. - */ - async postAllowSpendDeprecated( - l1Url: string, - signedAllowSpend: SignedAllowSpend - ) { - const l1Service = new RestApi(l1Url); - return l1Service.$post( - `/allow-spends`, - signedAllowSpend - ); - } - - /** - * @deprecated Use getTokenLockLastRef() instead. This method will be removed in the next major version. - */ - async getTokenLockLastRefDeprecated(l1Url: string, address: string) { - const l1Service = new RestApi(l1Url); - return l1Service.$get( - `/token-locks/last-reference/${address}` - ); - } - - /** - * @deprecated Use postTokenLock() instead. This method will be removed in the next major version. - */ - async postTokenLockDeprecated( - l1Url: string, - signedTokenLock: SignedTokenLock - ) { - const l1Service = new RestApi(l1Url); - return l1Service.$post( - `/token-locks`, - signedTokenLock - ); - } - async getAllowSpendLastRef(address: string) { return this.service.$get( `/allow-spends/last-reference/${address}` diff --git a/packages/dag4-wallet/src/dag-account.ts b/packages/dag4-wallet/src/dag-account.ts index 0ded810..053902f 100644 --- a/packages/dag4-wallet/src/dag-account.ts +++ b/packages/dag4-wallet/src/dag-account.ts @@ -35,11 +35,7 @@ import { networkConfig } from "./network-config"; import { allowSpend, tokenLock } from "./shared/operations"; import { normalizePublicKey } from "./utils"; import { - dagAddressValidator, - delegatedStakeSchema, - postAllowSpendSchema, - postTokenLockSchema, - validateArraySchema, + delegatedStakeSchema, validateSchema, withdrawDelegatedStakeSchema, } from "./validationSchemas"; @@ -531,109 +527,6 @@ export class DagAccount { return hashes; } - /** - * @deprecated Use createAllowSpend() instead. This method will be removed in the next major version. - */ - async postAllowSpend(body: { - source: string; - destination: string; - approvers: string[]; - amount: number; - fee: number; - currencyId: string | null; - validUntilEpoch: number; - tokenL1Url: string; - }) { - console.warn( - "postAllowSpend() is deprecated. Use createAllowSpend() instead." - ); - this.assertAccountIsActive(); - this.assertValidPrivateKey(); - - validateSchema(body, postAllowSpendSchema, true); - - // Validate approvers array - validateArraySchema(body.approvers, dagAddressValidator, true); - - const { - source, - destination, - approvers, - amount, - fee, - currencyId, - validUntilEpoch, - tokenL1Url, - } = body; - - if (source !== this.address) { - throw new Error('"source" must be the same as the account address'); - } - - let allowSpendLastRef: TransactionReference | null = null; - let signedAllowSpend: any | null = null; - let allowSpendResponse: { hash: string } | null = null; - - try { - // Get allow spend last reference - allowSpendLastRef = - await this.network.l1Api.getAllowSpendLastRefDeprecated( - tokenL1Url, - this.address - ); - } catch (err) { - console.error("Error getting the allow spend last reference"); - throw err; - } - - if (!allowSpendLastRef) { - throw new Error("Unable to find allow spend last reference"); - } - - try { - // Generate signed allow spend body - const allowSpendBody = { - source, - amount, - destination, - approvers, - parent: allowSpendLastRef, - lastValidEpochProgress: validUntilEpoch, - currencyId: currencyId ?? null, - fee: fee ?? 0, - }; - signedAllowSpend = await keyStore.generateBrotliSignature( - allowSpendBody, - normalizePublicKey(this.publicKey), - this.m_keyTrio.privateKey - ); - } catch (err) { - console.error("Error generating the signed allow spend"); - throw err; - } - - if (!signedAllowSpend) { - throw new Error("Unable to generate signed allow spend"); - } - - try { - // Post signed allow spend body - allowSpendResponse = await this.network.l1Api.postAllowSpendDeprecated( - tokenL1Url, - signedAllowSpend - ); - } catch (err) { - console.error("Error sending the allow spend transaction"); - throw err; - } - - if (!allowSpendResponse) { - throw new Error("Unable to get allow spend response"); - } - - return allowSpendResponse; - } - async createAllowSpend(body: AllowSpend, params?: Record) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -650,95 +543,6 @@ export class DagAccount { return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio, params); } - /** - * @deprecated Use createTokenLock() instead. This method will be removed in the next major version. - */ - async postTokenLock(body: { - source: string; - amount: number; - tokenL1Url: string; - unlockEpoch: number | null; - currencyId: string | null; - fee?: number; - replaceTokenLockRef: string | null; - }) { - console.warn( - "postTokenLock() is deprecated. Use createTokenLock() instead." - ); - this.assertAccountIsActive(); - this.assertValidPrivateKey(); - - validateSchema(body, postTokenLockSchema, true); - - const { amount, currencyId, fee, source, tokenL1Url, unlockEpoch, replaceTokenLockRef } = body; - - if (source !== this.address) { - throw new Error('"source" must be the same as the account address'); - } - - let tokenLockLastRef: TransactionReference | null = null; - let signedTokenLock: any | null = null; - let tokenLockResponse: { hash: string } | null = null; - - try { - // Get token lock last reference - tokenLockLastRef = await this.network.l1Api.getTokenLockLastRefDeprecated( - tokenL1Url, - this.address - ); - } catch (err) { - console.error("Error getting the token lock last reference"); - throw err; - } - - if (!tokenLockLastRef) { - throw new Error("Unable to find token lock last reference"); - } - - try { - // Generate signed token lock body - const tokenLockBody = { - source, - amount, - parent: tokenLockLastRef, - currencyId: currencyId ?? null, - fee: fee ?? 0, - unlockEpoch: unlockEpoch ?? null, - replaceTokenLockRef: replaceTokenLockRef ?? null, - }; - - signedTokenLock = await keyStore.generateBrotliSignature( - tokenLockBody, - normalizePublicKey(this.publicKey), - this.m_keyTrio.privateKey - ); - } catch (err) { - console.error("Error generating the signed token lock"); - throw err; - } - - if (!signedTokenLock) { - throw new Error("Unable to generate signed token lock"); - } - - try { - // Post signed token lock body - tokenLockResponse = await this.network.l1Api.postTokenLockDeprecated( - tokenL1Url, - signedTokenLock - ); - } catch (err) { - console.error("Error sending the token lock transaction"); - throw err; - } - - if (!tokenLockResponse) { - throw new Error("Unable to get token lock response"); - } - - return tokenLockResponse; - } - async createTokenLock(body: TokenLock, params?: Record) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -755,16 +559,6 @@ export class DagAccount { return tokenLock(bodyWithCurrencyId, this.network, this.keyTrio, params); } - /** - * @deprecated Use createDelegatedStake() instead. This method will be removed in the next major version. - */ - async postDelegatedStake(body: DelegatedStake) { - console.warn( - "postDelegatedStake() is deprecated. Use createDelegatedStake() instead." - ); - return this.createDelegatedStake(body); - } - async createDelegatedStake(body: DelegatedStake) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -832,16 +626,6 @@ export class DagAccount { return delegatedStakeResponse; } - /** - * @deprecated Use withdrawDelegatedStake() instead. This method will be removed in the next major version. - */ - async putWithdrawDelegatedStake(body: WithdrawDelegatedStake) { - console.warn( - "putWithdrawDelegatedStake() is deprecated. Use withdrawDelegatedStake() instead." - ); - return this.withdrawDelegatedStake(body); - } - async withdrawDelegatedStake(body: WithdrawDelegatedStake) { this.assertAccountIsActive(); this.assertValidPrivateKey(); diff --git a/packages/dag4-wallet/src/validationSchemas.ts b/packages/dag4-wallet/src/validationSchemas.ts index 6ab3306..ba841ee 100644 --- a/packages/dag4-wallet/src/validationSchemas.ts +++ b/packages/dag4-wallet/src/validationSchemas.ts @@ -52,14 +52,6 @@ export const allowSpendSchema = z.object({ .positive("Valid until epoch must be greater than zero"), }); -/** - * @deprecated Use allowSpendSchema instead. This schema will be removed in the next major version. - * Schema for validating post allow spend body - */ -export const postAllowSpendSchema = allowSpendSchema.extend({ - tokenL1Url: nonEmptyString, - currencyId: currencyIdValidator, -}); /** * Schema for validating token lock body @@ -80,14 +72,6 @@ export const tokenLockSchema = z.object({ }), }); -/** - * @deprecated Use tokenLockSchema instead. This schema will be removed in the next major version. - * Schema for validating post token lock body - */ -export const postTokenLockSchema = tokenLockSchema.extend({ - tokenL1Url: nonEmptyString, - currencyId: currencyIdValidator, -}); /** * Schema for validating delegated stake body From 3685f716540f2869fca67994a1f91aeab1324a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Su=C3=A1rez?= Date: Tue, 20 Jan 2026 13:57:06 -0500 Subject: [PATCH 2/4] fix: token lock replace is now optional, non-breaking --- packages/dag4-network/src/dto/v2/swap-operations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dag4-network/src/dto/v2/swap-operations.ts b/packages/dag4-network/src/dto/v2/swap-operations.ts index 11ecfe4..ec67fb9 100644 --- a/packages/dag4-network/src/dto/v2/swap-operations.ts +++ b/packages/dag4-network/src/dto/v2/swap-operations.ts @@ -28,7 +28,7 @@ export type TokenLock = { amount: number; fee?: number; unlockEpoch: number | null; - replaceTokenLockRef: string | null; + replaceTokenLockRef?: string | null; }; export type TokenLockWithCurrencyId = WithCurrencyId; From 64be9da223083018f8f180e198aede235320fc94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Su=C3=A1rez?= Date: Tue, 20 Jan 2026 14:23:42 -0500 Subject: [PATCH 3/4] revert: deprecated methods removal --- packages/dag4-network/src/api/v2/l1-api.ts | 35 +++++ packages/dag4-wallet/src/dag-account.ts | 123 ++++++++++++++++++ packages/dag4-wallet/src/validationSchemas.ts | 16 +++ 3 files changed, 174 insertions(+) diff --git a/packages/dag4-network/src/api/v2/l1-api.ts b/packages/dag4-network/src/api/v2/l1-api.ts index 76beef1..5d65e84 100644 --- a/packages/dag4-network/src/api/v2/l1-api.ts +++ b/packages/dag4-network/src/api/v2/l1-api.ts @@ -36,6 +36,41 @@ class L1Api { ); } + /** + * @deprecated Use getAllowSpendLastRef() instead. This method will be removed in the next major version. + */ + async getAllowSpendLastRefDeprecated(l1Url: string, address: string) { + const l1Service = new RestApi(l1Url); + return l1Service.$get( + `/allow-spends/last-reference/${address}` + ); + } + + /** + * @deprecated Use postAllowSpend() instead. This method will be removed in the next major version. + */ + async postAllowSpendDeprecated( + l1Url: string, + signedAllowSpend: SignedAllowSpend + ) { + const l1Service = new RestApi(l1Url); + return l1Service.$post( + `/allow-spends`, + signedAllowSpend + ); + } + + /** + * @deprecated Use getTokenLockLastRef() instead. This method will be removed in the next major version. + */ + async getTokenLockLastRefDeprecated(l1Url: string, address: string) { + const l1Service = new RestApi(l1Url); + return l1Service.$get( + `/token-locks/last-reference/${address}` + ); + } + + async getAllowSpendLastRef(address: string) { return this.service.$get( `/allow-spends/last-reference/${address}` diff --git a/packages/dag4-wallet/src/dag-account.ts b/packages/dag4-wallet/src/dag-account.ts index 053902f..9246f46 100644 --- a/packages/dag4-wallet/src/dag-account.ts +++ b/packages/dag4-wallet/src/dag-account.ts @@ -527,6 +527,109 @@ export class DagAccount { return hashes; } + /** + * @deprecated Use createAllowSpend() instead. This method will be removed in the next major version. + */ + async postAllowSpend(body: { + source: string; + destination: string; + approvers: string[]; + amount: number; + fee: number; + currencyId: string | null; + validUntilEpoch: number; + tokenL1Url: string; + }) { + console.warn( + "postAllowSpend() is deprecated. Use createAllowSpend() instead." + ); + this.assertAccountIsActive(); + this.assertValidPrivateKey(); + + validateSchema(body, postAllowSpendSchema, true); + + // Validate approvers array + validateArraySchema(body.approvers, dagAddressValidator, true); + + const { + source, + destination, + approvers, + amount, + fee, + currencyId, + validUntilEpoch, + tokenL1Url, + } = body; + + if (source !== this.address) { + throw new Error('"source" must be the same as the account address'); + } + + let allowSpendLastRef: TransactionReference | null = null; + let signedAllowSpend: any | null = null; + let allowSpendResponse: { hash: string } | null = null; + + try { + // Get allow spend last reference + allowSpendLastRef = + await this.network.l1Api.getAllowSpendLastRefDeprecated( + tokenL1Url, + this.address + ); + } catch (err) { + console.error("Error getting the allow spend last reference"); + throw err; + } + + if (!allowSpendLastRef) { + throw new Error("Unable to find allow spend last reference"); + } + + try { + // Generate signed allow spend body + const allowSpendBody = { + source, + amount, + destination, + approvers, + parent: allowSpendLastRef, + lastValidEpochProgress: validUntilEpoch, + currencyId: currencyId ?? null, + fee: fee ?? 0, + }; + signedAllowSpend = await keyStore.generateBrotliSignature( + allowSpendBody, + normalizePublicKey(this.publicKey), + this.m_keyTrio.privateKey + ); + } catch (err) { + console.error("Error generating the signed allow spend"); + throw err; + } + + if (!signedAllowSpend) { + throw new Error("Unable to generate signed allow spend"); + } + + try { + // Post signed allow spend body + allowSpendResponse = await this.network.l1Api.postAllowSpendDeprecated( + tokenL1Url, + signedAllowSpend + ); + } catch (err) { + console.error("Error sending the allow spend transaction"); + throw err; + } + + if (!allowSpendResponse) { + throw new Error("Unable to get allow spend response"); + } + + return allowSpendResponse; + } + async createAllowSpend(body: AllowSpend, params?: Record) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -559,6 +662,16 @@ export class DagAccount { return tokenLock(bodyWithCurrencyId, this.network, this.keyTrio, params); } + /** + * @deprecated Use createDelegatedStake() instead. This method will be removed in the next major version. + */ + async postDelegatedStake(body: DelegatedStake) { + console.warn( + "postDelegatedStake() is deprecated. Use createDelegatedStake() instead." + ); + return this.createDelegatedStake(body); + } + async createDelegatedStake(body: DelegatedStake) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -626,6 +739,16 @@ export class DagAccount { return delegatedStakeResponse; } + /** + * @deprecated Use withdrawDelegatedStake() instead. This method will be removed in the next major version. + */ + async putWithdrawDelegatedStake(body: WithdrawDelegatedStake) { + console.warn( + "putWithdrawDelegatedStake() is deprecated. Use withdrawDelegatedStake() instead." + ); + return this.withdrawDelegatedStake(body); + } + async withdrawDelegatedStake(body: WithdrawDelegatedStake) { this.assertAccountIsActive(); this.assertValidPrivateKey(); diff --git a/packages/dag4-wallet/src/validationSchemas.ts b/packages/dag4-wallet/src/validationSchemas.ts index ba841ee..6ab3306 100644 --- a/packages/dag4-wallet/src/validationSchemas.ts +++ b/packages/dag4-wallet/src/validationSchemas.ts @@ -52,6 +52,14 @@ export const allowSpendSchema = z.object({ .positive("Valid until epoch must be greater than zero"), }); +/** + * @deprecated Use allowSpendSchema instead. This schema will be removed in the next major version. + * Schema for validating post allow spend body + */ +export const postAllowSpendSchema = allowSpendSchema.extend({ + tokenL1Url: nonEmptyString, + currencyId: currencyIdValidator, +}); /** * Schema for validating token lock body @@ -72,6 +80,14 @@ export const tokenLockSchema = z.object({ }), }); +/** + * @deprecated Use tokenLockSchema instead. This schema will be removed in the next major version. + * Schema for validating post token lock body + */ +export const postTokenLockSchema = tokenLockSchema.extend({ + tokenL1Url: nonEmptyString, + currencyId: currencyIdValidator, +}); /** * Schema for validating delegated stake body From 1aee9b13a13678ecc52d46ce103f80dd9a970e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Su=C3=A1rez?= Date: Tue, 20 Jan 2026 14:33:01 -0500 Subject: [PATCH 4/4] fix: token lock replace support, flip TokenLock usage --- packages/dag4-network/src/api/v2/l1-api.ts | 13 +++ .../src/dto/v2/swap-operations.ts | 2 +- packages/dag4-wallet/src/dag-account.ts | 103 +++++++++++++++++- .../dag4-wallet/src/metagraph-token-client.ts | 4 +- packages/dag4-wallet/src/shared/operations.ts | 2 +- packages/dag4-wallet/src/validationSchemas.ts | 3 +- 6 files changed, 118 insertions(+), 9 deletions(-) diff --git a/packages/dag4-network/src/api/v2/l1-api.ts b/packages/dag4-network/src/api/v2/l1-api.ts index 5d65e84..3b8cd78 100644 --- a/packages/dag4-network/src/api/v2/l1-api.ts +++ b/packages/dag4-network/src/api/v2/l1-api.ts @@ -70,6 +70,19 @@ class L1Api { ); } + /** + * @deprecated Use postTokenLock() instead. This method will be removed in the next major version. + */ + async postTokenLockDeprecated( + l1Url: string, + signedTokenLock: SignedTokenLock + ) { + const l1Service = new RestApi(l1Url); + return l1Service.$post( + `/token-locks`, + signedTokenLock + ); + } async getAllowSpendLastRef(address: string) { return this.service.$get( diff --git a/packages/dag4-network/src/dto/v2/swap-operations.ts b/packages/dag4-network/src/dto/v2/swap-operations.ts index ec67fb9..11ecfe4 100644 --- a/packages/dag4-network/src/dto/v2/swap-operations.ts +++ b/packages/dag4-network/src/dto/v2/swap-operations.ts @@ -28,7 +28,7 @@ export type TokenLock = { amount: number; fee?: number; unlockEpoch: number | null; - replaceTokenLockRef?: string | null; + replaceTokenLockRef: string | null; }; export type TokenLockWithCurrencyId = WithCurrencyId; diff --git a/packages/dag4-wallet/src/dag-account.ts b/packages/dag4-wallet/src/dag-account.ts index 9246f46..6d6feb3 100644 --- a/packages/dag4-wallet/src/dag-account.ts +++ b/packages/dag4-wallet/src/dag-account.ts @@ -26,7 +26,9 @@ import { TokenLockResponse, TokenLockWithCurrencyId, TransactionReference, - WithdrawDelegatedStake + WithdrawDelegatedStake, + TokenLockWithParent, + SignedTokenLock } from "@stardust-collective/dag4-network"; import { BigNumber } from "bignumber.js"; import { Subject } from "rxjs"; @@ -35,7 +37,11 @@ import { networkConfig } from "./network-config"; import { allowSpend, tokenLock } from "./shared/operations"; import { normalizePublicKey } from "./utils"; import { - delegatedStakeSchema, + dagAddressValidator, + delegatedStakeSchema, + postAllowSpendSchema, + postTokenLockSchema, + validateArraySchema, validateSchema, withdrawDelegatedStakeSchema, } from "./validationSchemas"; @@ -646,7 +652,96 @@ export class DagAccount { return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio, params); } - async createTokenLock(body: TokenLock, params?: Record) { + /** + * @deprecated Use createTokenLock() instead. This method will be removed in the next major version. + */ + async postTokenLock(body: { + source: string; + amount: number; + tokenL1Url: string; + unlockEpoch: number | null; + currencyId: string | null; + fee?: number; + replaceTokenLockRef?: string | null; + }) { + console.warn( + "postTokenLock() is deprecated. Use createTokenLock() instead." + ); + this.assertAccountIsActive(); + this.assertValidPrivateKey(); + + validateSchema(body, postTokenLockSchema, true); + + const { amount, currencyId, fee, source, tokenL1Url, unlockEpoch, replaceTokenLockRef } = body; + + if (source !== this.address) { + throw new Error('"source" must be the same as the account address'); + } + + let tokenLockLastRef: TransactionReference | null = null; + let signedTokenLock: SignedTokenLock | null = null; + let tokenLockResponse: { hash: string } | null = null; + + try { + // Get token lock last reference + tokenLockLastRef = await this.network.l1Api.getTokenLockLastRefDeprecated( + tokenL1Url, + this.address + ); + } catch (err) { + console.error("Error getting the token lock last reference"); + throw err; + } + + if (!tokenLockLastRef) { + throw new Error("Unable to find token lock last reference"); + } + + try { + // Generate signed token lock body + const tokenLockBody: TokenLockWithParent = { + source, + amount, + parent: tokenLockLastRef, + currencyId: currencyId ?? null, + fee: fee ?? 0, + unlockEpoch: unlockEpoch ?? null, + replaceTokenLockRef: replaceTokenLockRef ?? null, + }; + + signedTokenLock = await keyStore.generateBrotliSignature( + tokenLockBody, + normalizePublicKey(this.publicKey), + this.m_keyTrio.privateKey + ); + } catch (err) { + console.error("Error generating the signed token lock"); + throw err; + } + + if (!signedTokenLock) { + throw new Error("Unable to generate signed token lock"); + } + + try { + // Post signed token lock body + tokenLockResponse = await this.network.l1Api.postTokenLockDeprecated( + tokenL1Url, + signedTokenLock + ); + } catch (err) { + console.error("Error sending the token lock transaction"); + throw err; + } + + if (!tokenLockResponse) { + throw new Error("Unable to get token lock response"); + } + + return tokenLockResponse; + } + + async createTokenLock(body: TokenLock & { replaceTokenLockRef?: string | null }, params?: Record) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -654,7 +749,7 @@ export class DagAccount { throw new Error("body must be a valid object"); } - const bodyWithCurrencyId: TokenLockWithCurrencyId = { + const bodyWithCurrencyId: TokenLockWithCurrencyId & { replaceTokenLockRef?: string | null } = { ...body, currencyId: null, }; diff --git a/packages/dag4-wallet/src/metagraph-token-client.ts b/packages/dag4-wallet/src/metagraph-token-client.ts index 813580a..ae6d611 100644 --- a/packages/dag4-wallet/src/metagraph-token-client.ts +++ b/packages/dag4-wallet/src/metagraph-token-client.ts @@ -266,7 +266,7 @@ class MetagraphTokenClient { return allowSpend(bodyWithCurrencyId, this.network, this.account.keyTrio, params); } - async createTokenLock(body: TokenLock, params?: Record) { + async createTokenLock(body: TokenLock & { replaceTokenLockRef?: string | null }, params?: Record) { this.account.assertAccountIsActive(); this.account.assertValidPrivateKey(); @@ -274,7 +274,7 @@ class MetagraphTokenClient { throw new Error("body must be a valid object"); } - const bodyWithCurrencyId: TokenLockWithCurrencyId = { + const bodyWithCurrencyId: TokenLockWithCurrencyId & { replaceTokenLockRef?: string | null } = { ...body, currencyId: this.networkInfo.metagraphId, }; diff --git a/packages/dag4-wallet/src/shared/operations.ts b/packages/dag4-wallet/src/shared/operations.ts index 8cfca5c..189818f 100644 --- a/packages/dag4-wallet/src/shared/operations.ts +++ b/packages/dag4-wallet/src/shared/operations.ts @@ -97,7 +97,7 @@ export const allowSpend = async ( }; export const tokenLock = async ( - body: TokenLockWithCurrencyId, + body: TokenLockWithCurrencyId & { replaceTokenLockRef?: string | null }, network: SharedNetwork, keyTrio: KeyTrio, params?: Record diff --git a/packages/dag4-wallet/src/validationSchemas.ts b/packages/dag4-wallet/src/validationSchemas.ts index 6ab3306..7bea8b5 100644 --- a/packages/dag4-wallet/src/validationSchemas.ts +++ b/packages/dag4-wallet/src/validationSchemas.ts @@ -77,7 +77,8 @@ export const tokenLockSchema = z.object({ .union([z.string(), z.null()]) .refine((value) => value === null || value !== "", { message: "Must be a valid hash or null", - }), + }) + .nullish(), }); /**