Skip to content

Commit

Permalink
feat: expose method for creating keypair
Browse files Browse the repository at this point in the history
  • Loading branch information
sampullman committed Oct 27, 2022
1 parent 63c86d7 commit 9c7b997
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions lib/node/emulator/test-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ transaction(_ pubKey: String) {
}
`

export const GET_KEY_CODE = `
pub fun main(address: Address, index: Int): AccountKey? {
let account = getAccount(address)
return account.keys.get(keyIndex: index)
}
`

export const formatPubKey = (
pubKey: string,
signatureAlgorithm = 2, // P256
Expand All @@ -60,6 +53,23 @@ export const pubFlowKey = async (privateKey: string): Promise<string> => {
return formatPubKey(publicKey)
}

export const createKeyPair = () => {
const key = ec.genKeyPair()
return key
}

export const createFlowAccount = async (
auth: IFlowAccount,
publicKey: string,
): Promise<void> => {
const args = [arg(formatPubKey(publicKey), t.String)]
await sendTransaction({
code: CREATE_ACCOUNT_CODE,
args,
auth: authorization(auth),
})
}

export class AccountManager {
accounts: Record<string, IFlowAccount> = {}
flowConfigObj: AnyJson = flowConfig()
Expand All @@ -84,13 +94,7 @@ export class AccountManager {
if (!address || !privateKey || !publicKey) {
throw new Error(`No address/key/pubKey found in ${path}`)
}

const args = [arg(formatPubKey(publicKey), t.String)]
await sendTransaction({
code: CREATE_ACCOUNT_CODE,
args,
auth: authorization(auth),
})
await createFlowAccount(auth, publicKey)

this.accounts[address] = {
address,
Expand Down

0 comments on commit 9c7b997

Please sign in to comment.