@dfns/sdk-keysigner 0.4.0-alpha.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +3 -8
  2. package/index.js +9 -13
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -1,15 +1,10 @@
1
- import { CredentialSigner, KeyAssertion, AllowCredential } from '@dfns/sdk';
1
+ import { CredentialSigner, KeyAssertion, UserActionChallenge } from '@dfns/sdk';
2
2
  export declare class AsymmetricKeySigner implements CredentialSigner<KeyAssertion> {
3
3
  private options;
4
4
  constructor(options: {
5
- privateKey: string;
6
5
  credId: string;
7
- appOrigin: string;
8
- crossOrigin?: boolean;
6
+ privateKey: string;
9
7
  algorithm?: string;
10
8
  });
11
- sign(challenge: string, allowCredentials: {
12
- key: AllowCredential[];
13
- webauthn: AllowCredential[];
14
- }): Promise<KeyAssertion>;
9
+ sign(challenge: UserActionChallenge): Promise<KeyAssertion>;
15
10
  }
package/index.js CHANGED
@@ -24,33 +24,29 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.AsymmetricKeySigner = void 0;
27
- const crypto = __importStar(require("crypto"));
27
+ const crypto = __importStar(require("node:crypto"));
28
+ const sdk_1 = require("@dfns/sdk");
28
29
  const utils_1 = require("@dfns/sdk/utils");
29
30
  class AsymmetricKeySigner {
30
31
  constructor(options) {
31
32
  this.options = options;
32
33
  }
33
- async sign(challenge, allowCredentials) {
34
- const credId = this.options.credId;
35
- if (credId === undefined || credId === '') {
36
- throw new Error('credId is needed to sign');
37
- }
38
- const allowedCredId = allowCredentials.key.map(cred => cred.id);
34
+ async sign(challenge) {
35
+ const { credId, privateKey, algorithm } = this.options;
36
+ const allowedCredId = challenge.allowCredentials.key.map((cred) => cred.id);
39
37
  if (!allowedCredId.includes(credId)) {
40
- throw new Error(`CredId ${credId} does not exist for this account: ${allowedCredId}`);
38
+ throw new sdk_1.DfnsError(-1, `${credId} does not match allowed credentials: ${allowedCredId}`);
41
39
  }
42
40
  const clientData = Buffer.from(JSON.stringify({
43
41
  type: 'key.get',
44
- challenge,
45
- origin: this.options.appOrigin,
46
- crossOrigin: this.options.crossOrigin ?? false,
42
+ challenge: challenge.challenge,
47
43
  }));
48
44
  return {
49
45
  kind: 'Key',
50
46
  credentialAssertion: {
51
- credId: this.options.credId,
47
+ credId,
52
48
  clientData: (0, utils_1.toBase64Url)(clientData),
53
- signature: (0, utils_1.toBase64Url)(crypto.sign(this.options.algorithm || undefined, clientData, this.options.privateKey)),
49
+ signature: (0, utils_1.toBase64Url)(crypto.sign(algorithm || undefined, clientData, privateKey)),
54
50
  },
55
51
  };
56
52
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@dfns/sdk-keysigner",
3
- "version": "0.4.0-alpha.1",
3
+ "version": "0.4.0",
4
4
  "dependencies": {
5
5
  "buffer": "6.0.3",
6
6
  "cross-fetch": "3.1.6",
7
7
  "uuid": "9.0.0"
8
8
  },
9
9
  "peerDependencies": {
10
- "@dfns/sdk": "0.4.0-alpha.1"
10
+ "@dfns/sdk": "0.4.0"
11
11
  },
12
12
  "main": "./index.js",
13
13
  "type": "commonjs"