@virtonetwork/authenticators-webauthn 1.1.2 → 1.1.4
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.
|
@@ -56,7 +56,7 @@ var InMemoryCredentialsHandler = /** @class */ (function () {
|
|
|
56
56
|
var credentials = (_a = this.userCredentials[userId]) !== null && _a !== void 0 ? _a : {};
|
|
57
57
|
return Object.entries(credentials).map(function (_a) {
|
|
58
58
|
var credential = _a[1];
|
|
59
|
-
return new Uint8Array(credential.rawId);
|
|
59
|
+
return new Uint8Array(credential.rawId).buffer;
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
62
|
InMemoryCredentialsHandler.prototype.onCreatedCredentials = function (userId, credential) {
|
package/dist/cjs/index.js
CHANGED
|
@@ -62,8 +62,8 @@ var WebAuthn = /** @class */ (function () {
|
|
|
62
62
|
* @param credentialsHandler - An implementation of {@link CredentialsHandler},
|
|
63
63
|
*
|
|
64
64
|
*/
|
|
65
|
-
function WebAuthn(userId, getChallenge,
|
|
66
|
-
|
|
65
|
+
function WebAuthn(userId, getChallenge, handler, addressGenerator) {
|
|
66
|
+
if (handler === void 0) { handler = new in_memory_credentials_handler_ts_1.InMemoryCredentialsHandler(); }
|
|
67
67
|
if (addressGenerator === void 0) { addressGenerator = signer_1.kreivoPassDefaultAddressGenerator; }
|
|
68
68
|
this.userId = userId;
|
|
69
69
|
this.getChallenge = getChallenge;
|
|
@@ -73,9 +73,10 @@ var WebAuthn = /** @class */ (function () {
|
|
|
73
73
|
* for all WebAuthn operations.
|
|
74
74
|
*/
|
|
75
75
|
this.hashedUserId = new Uint8Array(32);
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
76
|
+
var publicKeyCreateOptions = handler.publicKeyCreateOptions, publicKeyRequestOptions = handler.publicKeyRequestOptions, onCreatedCredentials = handler.onCreatedCredentials;
|
|
77
|
+
this.getPublicKeyCreateOptions = publicKeyCreateOptions.bind(handler);
|
|
78
|
+
this.getPublicKeyRequestOptions = publicKeyRequestOptions.bind(handler);
|
|
79
|
+
this.onCreatedCredentials = onCreatedCredentials.bind(handler);
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
82
|
* Pre‑computes {@link hashedUserId}.
|
|
@@ -138,7 +139,7 @@ var WebAuthn = /** @class */ (function () {
|
|
|
138
139
|
*/
|
|
139
140
|
WebAuthn.prototype.register = function (blockNumber_1) {
|
|
140
141
|
return __awaiter(this, arguments, void 0, function (blockNumber, displayName) {
|
|
141
|
-
var challenge, credentials, _a, _b, response,
|
|
142
|
+
var challenge, credentials, _a, _b, response, clientDataJSON, publicKey;
|
|
142
143
|
var _c, _d, _e;
|
|
143
144
|
if (displayName === void 0) { displayName = this.userId; }
|
|
144
145
|
return __generator(this, function (_f) {
|
|
@@ -149,7 +150,7 @@ var WebAuthn = /** @class */ (function () {
|
|
|
149
150
|
_b = (_a = navigator.credentials).create;
|
|
150
151
|
_c = {};
|
|
151
152
|
return [4 /*yield*/, this.getPublicKeyCreateOptions(challenge, {
|
|
152
|
-
id: this.hashedUserId,
|
|
153
|
+
id: this.hashedUserId.buffer,
|
|
153
154
|
name: this.userId,
|
|
154
155
|
displayName: displayName,
|
|
155
156
|
})];
|
|
@@ -158,7 +159,7 @@ var WebAuthn = /** @class */ (function () {
|
|
|
158
159
|
case 3:
|
|
159
160
|
credentials = (_f.sent());
|
|
160
161
|
response = credentials.response;
|
|
161
|
-
|
|
162
|
+
clientDataJSON = response.clientDataJSON;
|
|
162
163
|
publicKey = response.getPublicKey();
|
|
163
164
|
if (!publicKey) {
|
|
164
165
|
throw new Error("The credentials don't expose a public key. Please use another authenticator device.");
|
|
@@ -174,7 +175,7 @@ var WebAuthn = /** @class */ (function () {
|
|
|
174
175
|
case 5: return [2 /*return*/, (_d.meta = (_e.device_id = _f.sent(),
|
|
175
176
|
_e.context = blockNumber,
|
|
176
177
|
_e),
|
|
177
|
-
_d.authenticator_data = substrate_bindings_1.Binary.fromBytes(new Uint8Array(
|
|
178
|
+
_d.authenticator_data = substrate_bindings_1.Binary.fromBytes(new Uint8Array(response.getAuthenticatorData())),
|
|
178
179
|
_d.client_data = substrate_bindings_1.Binary.fromBytes(new Uint8Array(clientDataJSON)),
|
|
179
180
|
_d.public_key = substrate_bindings_1.Binary.fromBytes(new Uint8Array(publicKey)),
|
|
180
181
|
_d)];
|
|
@@ -12,7 +12,7 @@ export class InMemoryCredentialsHandler {
|
|
|
12
12
|
}
|
|
13
13
|
static credentialIds(userId) {
|
|
14
14
|
const credentials = this.userCredentials[userId] ?? {};
|
|
15
|
-
return Object.entries(credentials).map(([, credential]) => new Uint8Array(credential.rawId));
|
|
15
|
+
return Object.entries(credentials).map(([, credential]) => new Uint8Array(credential.rawId).buffer);
|
|
16
16
|
}
|
|
17
17
|
async onCreatedCredentials(userId, credential) {
|
|
18
18
|
InMemoryCredentialsHandler.tryMutate(userId, (credentials) => {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export declare class WebAuthn implements Authenticator<number> {
|
|
|
52
52
|
* @param credentialsHandler - An implementation of {@link CredentialsHandler},
|
|
53
53
|
*
|
|
54
54
|
*/
|
|
55
|
-
constructor(userId: string, getChallenge: Challenger<number>,
|
|
55
|
+
constructor(userId: string, getChallenge: Challenger<number>, handler?: CredentialsHandler, addressGenerator?: AddressGenerator);
|
|
56
56
|
/**
|
|
57
57
|
* Pre‑computes {@link hashedUserId}.
|
|
58
58
|
*
|
package/dist/esm/index.js
CHANGED
|
@@ -34,13 +34,14 @@ export class WebAuthn {
|
|
|
34
34
|
* @param credentialsHandler - An implementation of {@link CredentialsHandler},
|
|
35
35
|
*
|
|
36
36
|
*/
|
|
37
|
-
constructor(userId, getChallenge,
|
|
37
|
+
constructor(userId, getChallenge, handler = new InMemoryCredentialsHandler(), addressGenerator = kreivoPassDefaultAddressGenerator) {
|
|
38
38
|
this.userId = userId;
|
|
39
39
|
this.getChallenge = getChallenge;
|
|
40
40
|
this.addressGenerator = addressGenerator;
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
this.
|
|
41
|
+
const { publicKeyCreateOptions, publicKeyRequestOptions, onCreatedCredentials, } = handler;
|
|
42
|
+
this.getPublicKeyCreateOptions = publicKeyCreateOptions.bind(handler);
|
|
43
|
+
this.getPublicKeyRequestOptions = publicKeyRequestOptions.bind(handler);
|
|
44
|
+
this.onCreatedCredentials = onCreatedCredentials.bind(handler);
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* Pre‑computes {@link hashedUserId}.
|
|
@@ -80,13 +81,13 @@ export class WebAuthn {
|
|
|
80
81
|
const challenge = await this.getChallenge(blockNumber, this.addressGenerator(this.hashedUserId));
|
|
81
82
|
const credentials = (await navigator.credentials.create({
|
|
82
83
|
publicKey: await this.getPublicKeyCreateOptions(challenge, {
|
|
83
|
-
id: this.hashedUserId,
|
|
84
|
+
id: this.hashedUserId.buffer,
|
|
84
85
|
name: this.userId,
|
|
85
86
|
displayName,
|
|
86
87
|
}),
|
|
87
88
|
}));
|
|
88
89
|
const response = credentials.response;
|
|
89
|
-
const {
|
|
90
|
+
const { clientDataJSON } = response;
|
|
90
91
|
// Ensure publicKey is obtained in the registration process.
|
|
91
92
|
const publicKey = response.getPublicKey();
|
|
92
93
|
if (!publicKey) {
|
|
@@ -99,7 +100,7 @@ export class WebAuthn {
|
|
|
99
100
|
device_id: await this.getDeviceId(credentials),
|
|
100
101
|
context: blockNumber,
|
|
101
102
|
},
|
|
102
|
-
authenticator_data: Binary.fromBytes(new Uint8Array(
|
|
103
|
+
authenticator_data: Binary.fromBytes(new Uint8Array(response.getAuthenticatorData())),
|
|
103
104
|
client_data: Binary.fromBytes(new Uint8Array(clientDataJSON)),
|
|
104
105
|
public_key: Binary.fromBytes(new Uint8Array(publicKey)),
|
|
105
106
|
};
|
package/package.json
CHANGED