-
Notifications
You must be signed in to change notification settings - Fork 88
/
ecdsa.cy.js
44 lines (35 loc) · 1.44 KB
/
ecdsa.cy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { ECDSAKeyIdentity } from '@dfinity/identity';
import { get, set } from 'idb-keyval';
import { createActor } from '../utils/actor';
import ids from '../../.dfx/local/canister_ids.json';
const canisterId = ids.whoami.local;
const setup = async () => {
const identity1 = await ECDSAKeyIdentity.generate();
const whoami1 = createActor(ids.whoami.local, { agentOptions: { identity: identity1 } });
const principal1 = await whoami1.whoami();
return { principal1, whoami1, identity1 };
};
describe('ECDSAKeyIdentity tests with SubtleCrypto', () => {
it('generates a new identity', () => {
cy.visit('http://localhost:1234');
cy.window().then(async window => {
const { principal1 } = await setup();
const str = principal1.toString();
expect(str).to.be.an('string');
});
});
it('can persist an identity in indexeddb', () => {
cy.visit('http://localhost:1234');
cy.window().then(async window => {
const { principal1, identity1 } = await setup();
const str = principal1.toString();
expect(str).to.be.an('string');
await set('keyPair', identity1.getKeyPair());
const storedKeyPair = await get('keyPair');
const identity2 = await ECDSAKeyIdentity.fromKeyPair(storedKeyPair);
const whoami2 = createActor(canisterId, { agentOptions: { identity: identity2 } });
const principal2 = await whoami2.whoami();
expect(principal2.toString()).to.equal(str);
});
});
});