accounts
Version:
Tempo Accounts SDK
30 lines • 1.23 kB
JavaScript
import { PublicKey, Secp256k1 } from 'ox';
import { Account as TempoAccount } from 'viem/tempo';
/**
* Pure-JS secp256k1 keystore. The private key is held as hex in the handle
* and signing runs in JavaScript — at-rest protection is the host app's
* storage adapter, and the key is readable by anything with JS execution.
* Opt into it via `keyType: 'secp256k1'`; secp256k1 signatures are the
* chain's cheapest envelope.
*/
export function secp256k1() {
return {
async createKey() {
const privateKey = Secp256k1.randomPrivateKey();
return {
handle: { kind: 'secp256k1', privateKey },
publicKey: PublicKey.toHex(Secp256k1.getPublicKey({ privateKey })),
};
},
toAccount(record, context) {
const handle = record.handle;
if (handle?.kind !== 'secp256k1' || !handle.privateKey)
throw new Error('Unrecognized `secp256k1` keystore handle.');
return TempoAccount.fromSecp256k1(handle.privateKey, {
access: context.access,
keyAuthorizationManager: context.keyAuthorizationManager,
});
},
};
}
//# sourceMappingURL=secp256k1.js.map