Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waas: Add support for signTypedData intent #630

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/waas-ethers/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ export class SequenceSigner extends ethers.AbstractSigner {
): Promise<string> {
await this._ensureNetworkValid(false)

const typedDataDigest = ethers.TypedDataEncoder.encode(domain, types, value)

const args = {
message: typedDataDigest,
typedData: {
domain,
types,
message: value,
},
network: await this.getSimpleNetwork(),
...authArgs
}
return this.sequence.signMessage(args).then(response => response.data.signature)
return this.sequence.signTypedData(args).then(response => response.data.signature)
}

async signTransaction(_transaction: ethers.TransactionRequest): Promise<string> {
Expand Down
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
Loading