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

Using different owner and active key #4

Merged
merged 3 commits into from
Dec 5, 2024
Merged
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
23 changes: 16 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ export class AccountCreationPluginMetamask
qs.set('scope', String(context.appName))
}

const publicKey = await this.retrievePublicKey(currentChain.id)
const {ownerPublicKey, activePublicKey} = await this.retrievePublicKeys(currentChain.id)

qs.set('owner_key', String(publicKey))
qs.set('active_key', String(publicKey))
qs.set('owner_key', String(ownerPublicKey))
qs.set('active_key', String(activePublicKey))
const accountCreator = new AccountCreator({
supportedChains: [String(currentChain.id)],
fullCreationServiceUrl: `${this.accountCreationServiceUrl}?${qs.toString()}`,
Expand Down Expand Up @@ -135,16 +135,25 @@ export class AccountCreationPluginMetamask
}
}

async retrievePublicKey(chainId: Checksum256Type): Promise<PublicKey> {
async retrievePublicKeys(
chainId: Checksum256Type
): Promise<{ownerPublicKey: PublicKey; activePublicKey: PublicKey}> {
await this.initialize()
if (!this.provider) {
throw new Error('Metamask not found')
}
const result = (await this.invokeSnap({
method: 'antelope_getPublicKey',
const ownerPublicKeyString = (await this.invokeSnap({
method: 'antelope_getOwnerPublicKey',
params: {chainId: String(chainId)},
})) as string
return PublicKey.from(result)
const activePublicKeyString = (await this.invokeSnap({
method: 'antelope_getActivePublicKey',
params: {chainId: String(chainId)},
})) as string
return {
ownerPublicKey: PublicKey.from(ownerPublicKeyString),
activePublicKey: PublicKey.from(activePublicKeyString),
}
}

async request({method, params}) {
Expand Down
Loading