Skip to main content

Function: createIdentity()

createIdentity(seedPhrase): Identity

Create an Identity from a seed phrase. The seed phrase can be any arbitrary string.

The Identity is generated deterministically from the seed phrase, so subsequent calls to this function with the same seed phrase will produce the same Identity.

This is useful for tests where a persistent Identity is necessary but it's easier to store the seed phrase than the Identity itself.

Parameters

seedPhrase: string

The seed phrase to create the identity from. Can be any arbitrary string.

Returns

Identity

An identity created from the seed phrase.

See

Identity

Example

import { PocketIc, PocketIcServer, createIdentity } from '@hadronous/pic';
import { AnonymousIdentity } from '@dfinity/agent';
import { _SERVICE, idlFactory } from '../declarations';

const wasmPath = resolve('..', '..', 'canister.wasm');

const picServer = await PocketIcServer.create();
const pic = await PocketIc.create(picServer.getUrl());
const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
const { actor } = fixture;

const bob = createIdentity('SuperSecretSeedPhraseForBob');
actor.setIdentity(bob);

await pic.tearDown();
await picServer.stop();

Source

identity.ts:43