Skip to content

Commit

Permalink
waas: Add support for signTypedData intent
Browse files Browse the repository at this point in the history
  • Loading branch information
patrislav committed Dec 16, 2024
1 parent d900ebb commit e1fbf9f
Show file tree
Hide file tree
Showing 6 changed files with 374 additions and 159 deletions.
14 changes: 12 additions & 2 deletions packages/waas/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
SignMessageArgs,
getTimeDrift,
updateTimeDrift,
getLocalTime
getLocalTime,
SignTypedDataArgs
} from './intents'
import {
FeeOptionsResponse,
Expand All @@ -35,10 +36,12 @@ import {
isMaySentTransactionResponse,
isSessionAuthProofResponse,
isSignedMessageResponse,
isSignedTypedDataResponse,
isTimedOutTransactionResponse,
isValidationRequiredResponse,
MaySentTransactionResponse,
SignedMessageResponse
SignedMessageResponse,
SignedTypedDataResponse
} from './intents/responses'
import { WaasAuthenticator, AnswerIncorrectError, Chain, EmailAlreadyInUseError, Session } from './clients/authenticator.gen'
import { SimpleNetwork, WithSimpleNetwork } from './networks'
Expand Down Expand Up @@ -780,6 +783,13 @@ export class SequenceWaaS {
return this.trySendIntent(args, intent, isSignedMessageResponse)
}

async signTypedData(args: WithSimpleNetwork<SignTypedDataArgs> & CommonAuthArgs): Promise<SignedTypedDataResponse> {
await this.updateTimeDrift()

const intent = await this.waas.signTypedData(await this.useIdentifier(args))
return this.trySendIntent(args, intent, isSignedTypedDataResponse)
}

private async trySendTransactionIntent(
intent: SignedIntent<IntentDataSendTransaction>,
args: CommonAuthArgs
Expand Down
25 changes: 25 additions & 0 deletions packages/waas/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
signIntent,
signMessage,
SignMessageArgs,
signTypedData,
SignTypedDataArgs,
validateSession
} from './intents'
import { LocalStore, Store, StoreObj } from './store'
Expand All @@ -47,6 +49,7 @@ import {
IntentDataOpenSession,
IntentDataSendTransaction,
IntentDataSignMessage,
IntentDataSignTypedData,
IntentDataValidateSession
} from './clients/intent.gen'
import { getDefaultSubtleCryptoBackend, SubtleCryptoBackend } from './subtle-crypto'
Expand Down Expand Up @@ -422,6 +425,28 @@ export class SequenceWaaSBase {
return this.signIntent(packet)
}

/**
* This method can be used to sign typed data using waas API. It can only be used
* after successfully signing in with the `signIn` and `completeSignIn` methods.
*
* The method does not sign the typed data. It only returns a payload
* that must be sent to the waas API to complete the sign process.
*
* @param chainId The network on which the typed data will be signed
* @param typedData The typed data that will be signed
* @return a payload that must be sent to the waas API to complete sign process
*/
async signTypedData(args: WithSimpleNetwork<SignTypedDataArgs> & ExtraArgs): Promise<SignedIntent<IntentDataSignTypedData>> {
const packet = signTypedData({
chainId: toNetworkID(args.network || this.config.network),
...args,
lifespan: args.lifespan ?? DEFAULT_LIFESPAN,
wallet: await this.getWalletAddress()
})

return this.signIntent(packet)
}

/**
* This method can be used to send transactions to the waas API. It can only be used
* after successfully signing in with the `signIn` and `completeSignIn` methods.
Expand Down
Loading

0 comments on commit e1fbf9f

Please sign in to comment.