From a8aac194628e1d0ee5334218f6be8aa938b196ca Mon Sep 17 00:00:00 2001 From: Dawid Sowa Date: Tue, 22 Oct 2024 18:39:47 +0200 Subject: [PATCH] fix: adjust subintents to wallet api --- packages/dapp-toolkit/src/_types.ts | 2 - .../subintent-builder.spec.ts | 42 +++++++++++++------ .../subintent-builder.ts | 14 ++++--- .../modules/wallet-request/wallet-request.ts | 4 +- packages/dapp-toolkit/src/schemas/index.ts | 28 ++++++++----- 5 files changed, 57 insertions(+), 33 deletions(-) diff --git a/packages/dapp-toolkit/src/_types.ts b/packages/dapp-toolkit/src/_types.ts index bc4f670d..9c2dba77 100644 --- a/packages/dapp-toolkit/src/_types.ts +++ b/packages/dapp-toolkit/src/_types.ts @@ -4,8 +4,6 @@ import type { Observable } from 'rxjs' import type { RadixButtonStatus, RadixButtonTheme } from 'radix-connect-common' import { CallbackFns, - ExpireAfterSignature, - ExpireAtTime, Persona, PersonaDataName, WalletInteraction, diff --git a/packages/dapp-toolkit/src/modules/wallet-request/pre-authorization-request/subintent-builder.spec.ts b/packages/dapp-toolkit/src/modules/wallet-request/pre-authorization-request/subintent-builder.spec.ts index b36f85b9..6c719dc3 100644 --- a/packages/dapp-toolkit/src/modules/wallet-request/pre-authorization-request/subintent-builder.spec.ts +++ b/packages/dapp-toolkit/src/modules/wallet-request/pre-authorization-request/subintent-builder.spec.ts @@ -13,26 +13,44 @@ describe('SubintentRequestBuilder', () => { expect(tx).toEqual({ discriminator: 'subintent', version: 1, - transactionManifestVersion: 1, - transactionManifest: '...', + manifestVersion: 2, + subintentManifest: '...', expiration: { - discriminator: 'expireAfterSignature', - value: 60, + discriminator: 'expireAfterDelay', + expireAfterSeconds: 60, }, blobs: ['deadbeef', 'beefdead'], message: 'hello', }) }) + it('should build a subintent request with expiration at time', () => { + const tx = SubintentRequestBuilder() + .manifest('...') + .setExpiration('atTime', 1970) + .toRequestItem() + + expect(tx).toEqual({ + discriminator: 'subintent', + version: 1, + manifestVersion: 2, + subintentManifest: '...', + expiration: { + discriminator: 'expireAtTime', + unixTimestampSeconds: 1970, + }, + }) + }) + it('should build a subintent request using raw object', () => { const tx = SubintentRequestBuilder() .rawConfig({ version: 1, - transactionManifestVersion: 1, - transactionManifest: '...', + manifestVersion: 2, + subintentManifest: '...', expiration: { - discriminator: 'expireAfterSignature', - value: 60, + discriminator: 'expireAfterDelay', + expireAfterSeconds: 60, }, blobs: ['deadbeef', 'beefdead'], message: 'hello', @@ -42,11 +60,11 @@ describe('SubintentRequestBuilder', () => { expect(tx).toEqual({ discriminator: 'subintent', version: 1, - transactionManifestVersion: 1, - transactionManifest: '...', + manifestVersion: 2, + subintentManifest: '...', expiration: { - discriminator: 'expireAfterSignature', - value: 60, + discriminator: 'expireAfterDelay', + expireAfterSeconds: 60, }, blobs: ['deadbeef', 'beefdead'], message: 'hello', diff --git a/packages/dapp-toolkit/src/modules/wallet-request/pre-authorization-request/subintent-builder.ts b/packages/dapp-toolkit/src/modules/wallet-request/pre-authorization-request/subintent-builder.ts index 150a3675..a27964e0 100644 --- a/packages/dapp-toolkit/src/modules/wallet-request/pre-authorization-request/subintent-builder.ts +++ b/packages/dapp-toolkit/src/modules/wallet-request/pre-authorization-request/subintent-builder.ts @@ -21,7 +21,7 @@ export const SubintentRequestBuilder = () => { let state: Partial = { discriminator: 'subintent', version: 1, - transactionManifestVersion: 1, + manifestVersion: 2, } /** @@ -35,10 +35,12 @@ export const SubintentRequestBuilder = () => { type: 'atTime' | 'secondsAfterSignature', value: number, ) => { - state.expiration = { - discriminator: - type === 'atTime' ? 'expireAtTime' : 'expireAfterSignature', - value, + state.expiration = type === 'atTime' ? { + discriminator: 'expireAtTime', + unixTimestampSeconds: value, + } : { + discriminator: 'expireAfterDelay', + expireAfterSeconds: value } return api } @@ -72,7 +74,7 @@ export const SubintentRequestBuilder = () => { * @returns The API object for method chaining. */ const manifest = (value: string) => { - state.transactionManifest = value + state.subintentManifest = value return api } diff --git a/packages/dapp-toolkit/src/modules/wallet-request/wallet-request.ts b/packages/dapp-toolkit/src/modules/wallet-request/wallet-request.ts index c55a220b..54ecc3db 100644 --- a/packages/dapp-toolkit/src/modules/wallet-request/wallet-request.ts +++ b/packages/dapp-toolkit/src/modules/wallet-request/wallet-request.ts @@ -307,14 +307,14 @@ export const WalletRequestModule = (input: { > => { const walletInteraction = walletRequestSdk.createWalletInteraction({ discriminator: 'preAuthorizationRequest', - subintent: value.toRequestItem(), + request: value.toRequestItem(), }) return addNewRequest('preAuthorizationRequest', walletInteraction, false) .andThen(() => sendRequestAndAwaitResponse(walletInteraction)) .map((requestItem) => ({ signedPartialTransaction: - requestItem.walletResponse.signedPartialTransaction, + requestItem.walletResponse.response.signedPartialTransaction, })) } diff --git a/packages/dapp-toolkit/src/schemas/index.ts b/packages/dapp-toolkit/src/schemas/index.ts index b99072a4..f0f6cb3f 100644 --- a/packages/dapp-toolkit/src/schemas/index.ts +++ b/packages/dapp-toolkit/src/schemas/index.ts @@ -246,24 +246,30 @@ export const CancelRequest = object({ export type ExpireAtTime = InferOutput export const ExpireAtTime = object({ discriminator: literal('expireAtTime'), - value: number(), + unixTimestampSeconds: number(), }) -export type ExpireAfterSignature = InferOutput -export const ExpireAfterSignature = object({ - discriminator: literal('expireAfterSignature'), - value: number(), +export type ExpireAfterDelay = InferOutput +export const ExpireAfterDelay = object({ + discriminator: literal('expireAfterDelay'), + expireAfterSeconds: number(), }) export type SubintentRequestItem = InferOutput export const SubintentRequestItem = object({ discriminator: literal('subintent'), + /** + * Version of the message interface + */ version: number(), - transactionManifestVersion: number(), - transactionManifest: string(), + /** + * Version of the Transaction Manifest + */ + manifestVersion: number(), + subintentManifest: string(), blobs: optional(array(string())), message: optional(string()), - expiration: optional(union([ExpireAtTime, ExpireAfterSignature])), + expiration: optional(union([ExpireAtTime, ExpireAfterDelay])), }) export type SubintentResponseItem = InferOutput @@ -277,7 +283,7 @@ export type WalletPreAuthorizationItems = InferOutput< > export const WalletPreAuthorizationItems = object({ discriminator: literal('preAuthorizationRequest'), - subintent: optional(SubintentRequestItem), + request: optional(SubintentRequestItem), }) export type WalletInteractionItems = InferOutput @@ -334,8 +340,8 @@ export type WalletPreAuthorizationResponseItems = InferOutput< typeof WalletPreAuthorizationResponseItems > export const WalletPreAuthorizationResponseItems = object({ - discriminator: literal('preAuthorizationRequest'), - subintent: optional(SubintentResponseItem), + discriminator: literal('preAuthorizationResponse'), + response: optional(SubintentResponseItem), }) export const AuthLoginRequestResponseItem = union([