@dfns/sdk 0.3.4 → 0.4.0-alpha.2
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.
- package/baseAuthApi.d.ts +2 -16
- package/dfnsAuthenticator.js +3 -3
- package/package.json +1 -1
- package/signer.d.ts +21 -4
- package/utils/crypto.js +2 -1
- package/utils/fetch.js +3 -3
package/baseAuthApi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FirstFactorAttestation, RecoveryFactorAttestation, SecondFactorAttestation, UserRegistrationChallenge } from './store';
|
|
2
|
-
import {
|
|
2
|
+
import { CredentialKind, FirstFactorAssertion, RecoveryKeyAssertion, SecondFactorAssertion, UserActionChallenge } from './signer';
|
|
3
3
|
import { HttpMethod } from './utils/fetch';
|
|
4
4
|
export type DfnsBaseApiOptions = {
|
|
5
5
|
appId: string;
|
|
@@ -13,21 +13,7 @@ export type CreateUserActionChallengeRequest = {
|
|
|
13
13
|
userActionHttpPath: string;
|
|
14
14
|
userActionServerKind: 'Api';
|
|
15
15
|
};
|
|
16
|
-
export type
|
|
17
|
-
export type UserActionChallengeResponse = {
|
|
18
|
-
supportedCredentialKinds: {
|
|
19
|
-
kind: CredentialKind;
|
|
20
|
-
factor: CredentialFactor;
|
|
21
|
-
requiresSecondFactor: boolean;
|
|
22
|
-
}[];
|
|
23
|
-
challenge: string;
|
|
24
|
-
challengeIdentifier: string;
|
|
25
|
-
externalAuthenticationUrl: string;
|
|
26
|
-
allowCredentials: {
|
|
27
|
-
key: AllowCredential[];
|
|
28
|
-
webauthn: AllowCredential[];
|
|
29
|
-
};
|
|
30
|
-
};
|
|
16
|
+
export type UserActionChallengeResponse = UserActionChallenge;
|
|
31
17
|
export type SignUserActionChallengeRequest = {
|
|
32
18
|
challengeIdentifier: string;
|
|
33
19
|
firstFactor: FirstFactorAssertion;
|
package/dfnsAuthenticator.js
CHANGED
|
@@ -7,10 +7,10 @@ class DfnsAuthenticator {
|
|
|
7
7
|
this.apiOptions = apiOptions;
|
|
8
8
|
}
|
|
9
9
|
async login(request) {
|
|
10
|
-
const
|
|
11
|
-
const assertion = await this.apiOptions.signer.sign(challenge
|
|
10
|
+
const challenge = await baseAuthApi_1.BaseAuthApi.createUserLoginChallenge(request, this.apiOptions);
|
|
11
|
+
const assertion = await this.apiOptions.signer.sign(challenge);
|
|
12
12
|
return baseAuthApi_1.BaseAuthApi.createUserLogin({
|
|
13
|
-
challengeIdentifier,
|
|
13
|
+
challengeIdentifier: challenge.challengeIdentifier,
|
|
14
14
|
firstFactor: assertion,
|
|
15
15
|
}, this.apiOptions);
|
|
16
16
|
}
|
package/package.json
CHANGED
package/signer.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type CredentialFactor = 'first' | 'second' | 'either';
|
|
1
2
|
export type CredentialKind = 'Key' | 'Fido2' | 'Password' | 'Totp' | 'RecoveryKey';
|
|
2
3
|
export type CredentialTransport = 'usb' | 'nfc' | 'ble' | 'internal';
|
|
3
4
|
export type AllowCredential = {
|
|
@@ -5,6 +6,25 @@ export type AllowCredential = {
|
|
|
5
6
|
id: string;
|
|
6
7
|
transports: CredentialTransport[];
|
|
7
8
|
};
|
|
9
|
+
export type SupportedCredential = {
|
|
10
|
+
kind: CredentialKind;
|
|
11
|
+
factor: CredentialFactor;
|
|
12
|
+
requiresSecondFactor: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type UserActionChallenge = {
|
|
15
|
+
supportedCredentialKinds: SupportedCredential[];
|
|
16
|
+
rp: {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
};
|
|
20
|
+
challenge: string;
|
|
21
|
+
challengeIdentifier: string;
|
|
22
|
+
externalAuthenticationUrl: string;
|
|
23
|
+
allowCredentials: {
|
|
24
|
+
key: AllowCredential[];
|
|
25
|
+
webauthn: AllowCredential[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
8
28
|
export type KeyAssertion = {
|
|
9
29
|
kind: 'Key';
|
|
10
30
|
credentialAssertion: {
|
|
@@ -45,8 +65,5 @@ export type FirstFactorAssertion = KeyAssertion | Fido2Assertion | PasswordAsser
|
|
|
45
65
|
export type SecondFactorAssertion = KeyAssertion | Fido2Assertion | TotpAssertion;
|
|
46
66
|
export type CredentialAssertion = KeyAssertion | Fido2Assertion | PasswordAssertion | TotpAssertion;
|
|
47
67
|
export interface CredentialSigner<T extends CredentialAssertion = FirstFactorAssertion> {
|
|
48
|
-
sign(challenge:
|
|
49
|
-
key: AllowCredential[];
|
|
50
|
-
webauthn: AllowCredential[];
|
|
51
|
-
}): Promise<T>;
|
|
68
|
+
sign(challenge: UserActionChallenge): Promise<T>;
|
|
52
69
|
}
|
package/utils/crypto.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rawSignatureToAns1 = exports.exportPublicKeyInPemFormatBrowser = void 0;
|
|
4
|
+
const buffer_1 = require("buffer");
|
|
4
5
|
const base64_1 = require("./base64");
|
|
5
6
|
const string_1 = require("./string");
|
|
6
7
|
const bigint_1 = require("./bigint");
|
|
@@ -8,7 +9,7 @@ const bigint_1 = require("./bigint");
|
|
|
8
9
|
// Adding `Browser` in the function name to distinguish with native node crypto module usage
|
|
9
10
|
const exportPublicKeyInPemFormatBrowser = async (key) => {
|
|
10
11
|
const exported = await crypto.subtle.exportKey('spki', key.publicKey);
|
|
11
|
-
const b64Exported = (0, base64_1.toBase64)(Buffer.from(exported));
|
|
12
|
+
const b64Exported = (0, base64_1.toBase64)(buffer_1.Buffer.from(exported));
|
|
12
13
|
const pem = `-----BEGIN PUBLIC KEY-----\n${(0, string_1.splitString)(b64Exported).join("\n")}\n-----END PUBLIC KEY-----`;
|
|
13
14
|
return pem;
|
|
14
15
|
};
|
package/utils/fetch.js
CHANGED
|
@@ -83,15 +83,15 @@ const userAction = (fetch) => {
|
|
|
83
83
|
...options.apiOptions,
|
|
84
84
|
baseUrl: options.apiOptions.baseAuthUrl || options.apiOptions.baseUrl,
|
|
85
85
|
};
|
|
86
|
-
const
|
|
86
|
+
const challenge = await baseAuthApi_1.BaseAuthApi.createUserActionChallenge({
|
|
87
87
|
userActionPayload: options.body ?? '',
|
|
88
88
|
userActionHttpMethod: options.method,
|
|
89
89
|
userActionHttpPath: resource.pathname,
|
|
90
90
|
userActionServerKind: apiOptions?.userActionServerKind || 'Api',
|
|
91
91
|
}, apiOptions);
|
|
92
|
-
const assertion = await apiOptions.signer.sign(challenge
|
|
92
|
+
const assertion = await apiOptions.signer.sign(challenge);
|
|
93
93
|
const { userAction } = await baseAuthApi_1.BaseAuthApi.signUserActionChallenge({
|
|
94
|
-
challengeIdentifier,
|
|
94
|
+
challengeIdentifier: challenge.challengeIdentifier,
|
|
95
95
|
firstFactor: assertion,
|
|
96
96
|
}, apiOptions);
|
|
97
97
|
options.headers = {
|