Skip to content

Commit

Permalink
enhancement: deriving a different owner key
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Jul 24, 2024
1 parent 72b5215 commit 98bc931
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,29 @@ export class WalletPluginMetaMask extends AbstractWalletPlugin implements Wallet
return context.permissionLevel
}

const publicKey = await this.retrievePublicKey(chain.id)
const accounts = await this.lookupAccounts(publicKey, chain.id)
const activeKey = await this.retrievePublicKey(chain.id, 1)
console.log({activeKey: String(activeKey)})
const accounts = await this.lookupAccounts(activeKey, chain.id)

if (!context.ui) {
throw new Error('UI not found')
}

return new Promise((resolve) => {
function createAccount() {
const createAccount = async () => {
// Changed to arrow function
const qs = new URLSearchParams()
qs.set('supported_chains', String(chain))
if (context.appName) {
qs.set('scope', String(context.appName))
}
qs.set('owner_key', String(publicKey))
qs.set('active_key', String(publicKey))

const ownerKey = await this.retrievePublicKey(chain.id, 0)

console.log({ownerKey: String(ownerKey)})

qs.set('owner_key', String(ownerKey))
qs.set('active_key', String(activeKey))
const accountCreator = new AccountCreator({
supportedChains: [String(chain.id)],
fullCreationServiceUrl: `${ACCOUNT_CREATION_SERVICE_URL}?${qs.toString()}`,
Expand All @@ -123,6 +130,7 @@ export class WalletPluginMetaMask extends AbstractWalletPlugin implements Wallet
}
})
}

context.ui.prompt({
title: accounts.length ? 'Select an account' : 'No accounts found',
body: '',
Expand Down Expand Up @@ -204,14 +212,14 @@ export class WalletPluginMetaMask extends AbstractWalletPlugin implements Wallet
}
}

async retrievePublicKey(chainId: Checksum256Type): Promise<PublicKey> {
async retrievePublicKey(chainId: Checksum256Type, addressIndex = 0): Promise<PublicKey> {
await this.initialize()
if (!this.provider) {
throw new Error('Metamask not found')
}
const result = (await this.invokeSnap({
method: 'antelope_getPublicKey',
params: {chainId: String(chainId)},
params: {chainId: String(chainId), addressIndex},
})) as string
return PublicKey.from(result)
}
Expand Down

0 comments on commit 98bc931

Please sign in to comment.