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 child wallet adoption #609

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 24 additions & 1 deletion packages/waas/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import {
SignedIntent,
SignMessageArgs,
getTimeDrift,
updateTimeDrift
updateTimeDrift,
AdoptChildWalletArgs
} from './intents'
import {
FeeOptionsResponse,
isChildWalletAdoptedResponse,
isCloseSessionResponse,
isFeeOptionsResponse,
isFinishValidateSessionResponse,
isGetAdopterResponse,
isGetIdTokenResponse,
isGetSessionResponse,
isInitiateAuthResponse,
Expand Down Expand Up @@ -738,6 +741,19 @@ export class SequenceWaaS {
return res.data
}

async getAdopter(): Promise<string> {
await this.updateTimeDrift()

const intent = await this.waas.getAdopter()
const res = await this.sendIntent(intent)

if (!isGetAdopterResponse(res)) {
throw new Error(`Invalid response: ${JSON.stringify(res)}`)
}

return res.data.adopterAddress
}

async useIdentifier<T extends CommonAuthArgs>(args: T): Promise<T & { identifier: string }> {
if (args.identifier) {
return args as T & { identifier: string }
Expand Down Expand Up @@ -844,6 +860,13 @@ export class SequenceWaaS {
return this.trySendIntent(args, intent, isFeeOptionsResponse)
}

async adoptChildWallet(args: WithSimpleNetwork<AdoptChildWalletArgs> & CommonAuthArgs) {
await this.updateTimeDrift()

const intent = await this.waas.adoptChildWallet(args)
return this.trySendIntent(args, intent, isChildWalletAdoptedResponse)
}

async networkList(): Promise<NetworkList> {
const networks: NetworkList = []
const chainList = await this.client.chainList({
Expand Down
20 changes: 20 additions & 0 deletions packages/waas/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {
adoptChildWallet,
AdoptChildWalletArgs,
changeIntentTime,
closeSession,
combineTransactionIntents,
feeOptions,
finishValidateSession,
getAdopter,
getIdToken,
getSession,
getTransactionReceipt,
Expand Down Expand Up @@ -589,6 +592,23 @@ export class SequenceWaaSBase {
return this.signIntent(intent)
}

async adoptChildWallet(args: WithSimpleNetwork<AdoptChildWalletArgs>) {
const intent = adoptChildWallet({
wallet: await this.getWalletAddress(),
...args,
lifespan: DEFAULT_LIFESPAN,
})
return this.signIntent(intent)
}

async getAdopter() {
const intent = getAdopter({
wallet: await this.getWalletAddress(),
lifespan: DEFAULT_LIFESPAN,
})
return this.signIntent(intent)
}

async batch(intents: Intent<IntentDataSendTransaction>[]): Promise<SignedIntent<IntentDataSendTransaction>> {
const combined = combineTransactionIntents(intents)
return this.signIntent(combined)
Expand Down
Loading