Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ECDSAKeyIdentity #591

Merged
merged 54 commits into from Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
eb509f6
wip
krpeacock Jun 28, 2022
60dc610
feat: jwk support for ecdsa
krpeacock Jun 29, 2022
20b28dd
wip
krpeacock Jul 1, 2022
eb41716
supports DER-encoding
krpeacock Jul 6, 2022
2e91698
ECDSAKeyIdentity
krpeacock Jul 6, 2022
b5a0441
upgrading packages
krpeacock Jul 6, 2022
409c5ce
working e2e call
krpeacock Jul 7, 2022
e8e7bea
allow providing a SubtleCrypto interface
krpeacock Jul 11, 2022
1564116
tests passing
krpeacock Jul 11, 2022
1e3328b
fixing authclient tests after jest update
krpeacock Jul 11, 2022
20da536
Merge branch 'main' into SDK-554-ecdsakeyidentity
krpeacock Jul 11, 2022
bd05f9b
changelog and readme
krpeacock Jul 11, 2022
cfbb6bb
ECDSAPublicKey docs
krpeacock Jul 11, 2022
2f0f37a
docs for ECDSAKeyIdentity
krpeacock Jul 11, 2022
f322446
pulling lint out to separate job
krpeacock Jul 12, 2022
9d427ef
remove todo
krpeacock Jul 12, 2022
587739b
tweaking lint job
krpeacock Jul 12, 2022
23c0e28
fixing package.json
krpeacock Jul 12, 2022
508e3e5
switching to isomomorphic-fetch
krpeacock Jul 12, 2022
97f9352
switch over to miracl_core (#590)
Daniel-Bloom-dfinity Jul 12, 2022
968530c
chore: aggregate test results for required statuses (#592)
ericswanson-dfinity Jul 12, 2022
32027b3
feat: enables inline sourcemaps for packages for developer experience…
krpeacock Jul 13, 2022
05e12ec
chore: release 0.12.1 (#594)
krpeacock Jul 13, 2022
2d7e126
wip
krpeacock Jun 28, 2022
94b673f
feat: jwk support for ecdsa
krpeacock Jun 29, 2022
25fb4eb
wip
krpeacock Jul 1, 2022
87e70fb
supports DER-encoding
krpeacock Jul 6, 2022
8e1b800
ECDSAKeyIdentity
krpeacock Jul 6, 2022
af86e13
upgrading packages
krpeacock Jul 6, 2022
fa207f5
working e2e call
krpeacock Jul 7, 2022
dac0f8a
allow providing a SubtleCrypto interface
krpeacock Jul 11, 2022
6efbe94
tests passing
krpeacock Jul 11, 2022
44907fb
fixing authclient tests after jest update
krpeacock Jul 11, 2022
6c9c445
changelog and readme
krpeacock Jul 11, 2022
b0966ce
ECDSAPublicKey docs
krpeacock Jul 11, 2022
d8461f3
docs for ECDSAKeyIdentity
krpeacock Jul 11, 2022
d79f352
pulling lint out to separate job
krpeacock Jul 12, 2022
e4c1c80
remove todo
krpeacock Jul 12, 2022
7337365
tweaking lint job
krpeacock Jul 12, 2022
a6edab0
switching to isomomorphic-fetch
krpeacock Jul 12, 2022
d1e08e4
Merge branch 'SDK-554-ecdsakeyidentity' of https://github.com/dfinity…
krpeacock Jul 14, 2022
1539e15
resolving merge conflicts
krpeacock Jul 14, 2022
b8c732f
using spki encoding for DER-encoding
krpeacock Jul 18, 2022
21c6d08
using spki encoding for DER-encoding
krpeacock Jul 18, 2022
f8339c2
Merge branch 'SDK-554-ecdsakeyidentity' of https://github.com/dfinity…
krpeacock Jul 18, 2022
2e7e7b5
clarifies that public keys are always extractable
krpeacock Jul 18, 2022
84f1070
updating snapshots
krpeacock Jul 18, 2022
d6b9d89
e2e browser tests for identity
krpeacock Jul 20, 2022
b666291
updating browser scripts
krpeacock Jul 20, 2022
d24668f
e2e tests exit code
krpeacock Jul 20, 2022
66b2f42
fixing lint
krpeacock Jul 20, 2022
bdf6cc6
backgorund task
krpeacock Jul 20, 2022
9223271
refactoring out redundant publickey
krpeacock Jul 22, 2022
b47d05c
removes references to ECDSAKeyIdentity
krpeacock Jul 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/e2e-tests.yml
Expand Up @@ -31,7 +31,6 @@ jobs:
- run: npm install -g npm

- run: npm install
- run: npm run lint --workspaces --if-present

# build monorepo incl. each subpackage
- run: npm run build --workspaces --if-present
Expand All @@ -47,3 +46,13 @@ jobs:
env:
CI: true
REPLICA_PORT: 8000

aggregate:
name: e2e:required
if: ${{ always() }}
needs: [ test ]
runs-on: ubuntu-latest
steps:
- name: check e2e test result
if: ${{ needs.test.result != 'success' }}
run: exit 1
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
@@ -0,0 +1,30 @@
name: Check Lint
on:
pull_request:
types:
- opened
- reopened
- edited
- synchronize

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-18.04]
ghc: ['8.8.4']
spec:
- release-0.16 # https://github.com/dfinity-lab/ic-ref/tree/release-0.16
node:
- 14
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install -g npm
- run: npm install
- run: npm run lint --workspaces --if-present
10 changes: 10 additions & 0 deletions .github/workflows/mitm.yml
Expand Up @@ -63,3 +63,13 @@ jobs:
REPLICA_PORT: 8888
MITM: true
run: npm run mitm --workspaces --if-present

aggregate:
name: mitm:required
if: ${{ always() }}
needs: [ test ]
runs-on: ubuntu-latest
steps:
- name: check e2e test result
if: ${{ needs.test.result != 'success' }}
run: exit 1
10 changes: 10 additions & 0 deletions .github/workflows/prettier.yml
Expand Up @@ -28,3 +28,13 @@ jobs:
- run: npm install -g npm
- run: npm install prettier pretty-quick
- run: npm run prettier:check

aggregate:
name: format:required
if: ${{ always() }}
needs: [ test ]
runs-on: ubuntu-latest
steps:
- name: check e2e test result
if: ${{ needs.test.result != 'success' }}
run: exit 1
11 changes: 10 additions & 1 deletion .github/workflows/unit-tests.yml
Expand Up @@ -33,7 +33,6 @@ jobs:
- run: npm install -g npm

- run: npm install
- run: npm run lint --workspaces --if-present

# build monorepo incl. each subpackage
- run: npm run build --workspaces --if-present
Expand All @@ -42,3 +41,13 @@ jobs:
- run: npm run test
env:
CI: true

aggregate:
name: unit:required
if: ${{ always() }}
needs: [ test ]
runs-on: ubuntu-latest
steps:
- name: check e2e test result
if: ${{ needs.test.result != 'success' }}
run: exit 1
13 changes: 7 additions & 6 deletions demos/ledgerhq/package.json
Expand Up @@ -2,18 +2,19 @@
"name": "ic-agent-ledgerhq-app",
"private": true,
"dependencies": {
"@dfinity/agent": "^0.12.0",
"@dfinity/authentication": "^0.12.0",
"@dfinity/identity": "^0.12.0",
"@dfinity/identity-ledgerhq": "^0.12.0",
"@dfinity/principal": "^0.12.0",
"@dfinity/agent": "^0.12.1",
"@dfinity/authentication": "^0.12.1",
"@dfinity/identity": "^0.12.1",
"@dfinity/identity-ledgerhq": "^0.12.1",
"@dfinity/principal": "^0.12.1",
"assert": "^2.0.0",
"buffer": "^6.0.3",
"events": "^3.2.0",
"html-webpack-plugin": "^5.1.0",
"process": "^0.11.10",
"protobufjs": "^6.10.2",
"stream-browserify": "^3.0.0",
"ts-node": "^10.8.2",
"util": "^0.12.3",
"webpack": "^5.24.1",
"webpack-cli": "^4.5.0",
Expand All @@ -27,5 +28,5 @@
"test:coverage": "",
"test": ""
},
"version": "0.12.0"
"version": "0.12.1"
}
11 changes: 6 additions & 5 deletions demos/sample-javascript/package.json
Expand Up @@ -2,15 +2,16 @@
"name": "ic-agent-sample-javascript-app",
"private": true,
"dependencies": {
"@dfinity/agent": "^0.12.0",
"@dfinity/authentication": "^0.12.0",
"@dfinity/identity": "^0.12.0",
"@dfinity/principal": "^0.12.0",
"@dfinity/agent": "^0.12.1",
"@dfinity/authentication": "^0.12.1",
"@dfinity/identity": "^0.12.1",
"@dfinity/principal": "^0.12.1",
"assert": "^2.0.0",
"events": "^3.2.0",
"html-webpack-plugin": "^5.1.0",
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"ts-node": "^10.8.2",
"util": "^0.12.3",
"webpack": "^5.24.1",
"webpack-cli": "^4.5.0",
Expand All @@ -24,5 +25,5 @@
"test:coverage": "",
"test": ""
},
"version": "0.12.0"
"version": "0.12.1"
}
11 changes: 11 additions & 0 deletions docs/generated/changelog.html
Expand Up @@ -10,8 +10,19 @@
<h1>Agent-JS Changelog</h1>

<section>
<h2>Version 0.12.2</h2>
<ul>
<li>
Support for the SubtleCrypto interface in @dfinity/identity using the new ECDSAKeyIdentity
</li>
</ul>
<h2>Version 0.12.1</h2>
<ul>
<li>Adds inline sourcemaps to packages</li>
<li>
Pulls lint out to a separate job now that Node 12 is failing with latest eslint
dependencies
</li>
<li>Adds UTF-8 as an encoding option for CanisterStatus custom paths</li>
<li>
Adds a public method "createReadStateRequest" that creates the request for "readState".
Expand Down
2 changes: 2 additions & 0 deletions e2e/browser/.gitignore
@@ -0,0 +1,2 @@
.parcel-cache
src/declarations
5 changes: 5 additions & 0 deletions e2e/browser/.proxyrc
@@ -0,0 +1,5 @@
{
"/api": {
"target": "http://localhost:8000/",
}
}
12 changes: 12 additions & 0 deletions e2e/browser/cypress.config.js
@@ -0,0 +1,12 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const { defineConfig } = require('cypress');

module.exports = defineConfig({
video: false,
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
6 changes: 6 additions & 0 deletions e2e/browser/cypress/.eslintrc.json
@@ -0,0 +1,6 @@
{
"plugins": ["cypress"],
"env": {
"cypress/globals": true
}
}
44 changes: 44 additions & 0 deletions e2e/browser/cypress/e2e/ecdsa.cy.js
@@ -0,0 +1,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);
});
});
});
5 changes: 5 additions & 0 deletions e2e/browser/cypress/fixtures/example.json
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions e2e/browser/cypress/support/commands.js
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions e2e/browser/cypress/support/e2e.js
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
25 changes: 25 additions & 0 deletions e2e/browser/cypress/utils/actor.js
@@ -0,0 +1,25 @@
import { Actor, HttpAgent } from '@dfinity/agent';

// Imports and re-exports candid interface
import { idlFactory } from '../../src/declarations/whoami/whoami.did.js';
export { idlFactory } from '../../src/declarations/whoami/whoami.did.js';
// CANISTER_ID is replaced by webpack based on node environment

/**
*
* @param {string | import("@dfinity/principal").Principal} canisterId Canister ID of Agent
* @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig}} [options]
* @return {import("@dfinity/agent").ActorSubclass<import("./whoami.did.js")._SERVICE>}
*/
export const createActor = (canisterId, options) => {
const agent = new HttpAgent({ ...options?.agentOptions });

agent.fetchRootKey();

// Creates an actor with using the candid interface and the HttpAgent
return Actor.createActor(idlFactory, {
agent,
canisterId,
...options?.actorOptions,
});
};
8 changes: 8 additions & 0 deletions e2e/browser/dfx.json
@@ -0,0 +1,8 @@
{
"canisters": {
"whoami": {
"type": "motoko",
"main": "src/whoami/main.mo"
}
}
}