@virtonetwork/authenticators-webauthn 1.0.8 → 1.1.1

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/dist/cjs/index.js CHANGED
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.WebAuthn = exports.KREIVO_AUTHORITY_ID = exports.InMemoryCredentialsHandler = void 0;
40
+ var signer_1 = require("@virtonetwork/signer");
40
41
  var substrate_bindings_1 = require("@polkadot-api/substrate-bindings");
41
42
  var types_ts_1 = require("./types.js");
42
43
  var in_memory_credentials_handler_ts_1 = require("./in-memory-credentials-handler.js");
@@ -61,10 +62,12 @@ var WebAuthn = /** @class */ (function () {
61
62
  * @param credentialsHandler - An implementation of {@link CredentialsHandler},
62
63
  *
63
64
  */
64
- function WebAuthn(userId, getChallenge, _a) {
65
+ function WebAuthn(userId, getChallenge, addressGenerator, _a) {
66
+ if (addressGenerator === void 0) { addressGenerator = signer_1.kreivoPassDefaultAddressGenerator; }
65
67
  var _b = _a === void 0 ? new in_memory_credentials_handler_ts_1.InMemoryCredentialsHandler() : _a, publicKeyCreateOptions = _b.publicKeyCreateOptions, publicKeyRequestOptions = _b.publicKeyRequestOptions, onCreatedCredentials = _b.onCreatedCredentials;
66
68
  this.userId = userId;
67
69
  this.getChallenge = getChallenge;
70
+ this.addressGenerator = addressGenerator;
68
71
  /**
69
72
  * SHA‑256 hash of {@link userId}. Filled once by {@link setup} and reused
70
73
  * for all WebAuthn operations.
@@ -140,7 +143,7 @@ var WebAuthn = /** @class */ (function () {
140
143
  if (displayName === void 0) { displayName = this.userId; }
141
144
  return __generator(this, function (_f) {
142
145
  switch (_f.label) {
143
- case 0: return [4 /*yield*/, this.getChallenge(blockNumber, new Uint8Array([]))];
146
+ case 0: return [4 /*yield*/, this.getChallenge(blockNumber, this.addressGenerator(this.hashedUserId))];
144
147
  case 1:
145
148
  challenge = _f.sent();
146
149
  _b = (_a = navigator.credentials).create;
@@ -1,3 +1,4 @@
1
+ import { AddressGenerator } from "@virtonetwork/signer";
1
2
  /**
2
3
  * WebAuthn pass‑key authenticator for Virto Network.
3
4
  *
@@ -34,6 +35,7 @@ export declare const KREIVO_AUTHORITY_ID: Binary;
34
35
  export declare class WebAuthn implements Authenticator<number> {
35
36
  readonly userId: string;
36
37
  readonly getChallenge: Challenger<number>;
38
+ readonly addressGenerator: AddressGenerator;
37
39
  /**
38
40
  * SHA‑256 hash of {@link userId}. Filled once by {@link setup} and reused
39
41
  * for all WebAuthn operations.
@@ -50,7 +52,7 @@ export declare class WebAuthn implements Authenticator<number> {
50
52
  * @param credentialsHandler - An implementation of {@link CredentialsHandler},
51
53
  *
52
54
  */
53
- constructor(userId: string, getChallenge: Challenger<number>, { publicKeyCreateOptions, publicKeyRequestOptions, onCreatedCredentials, }?: CredentialsHandler);
55
+ constructor(userId: string, getChallenge: Challenger<number>, addressGenerator?: AddressGenerator, { publicKeyCreateOptions, publicKeyRequestOptions, onCreatedCredentials, }?: CredentialsHandler);
54
56
  /**
55
57
  * Pre‑computes {@link hashedUserId}.
56
58
  *
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { kreivoPassDefaultAddressGenerator, } from "@virtonetwork/signer";
1
2
  import { Binary, Blake2256 } from "@polkadot-api/substrate-bindings";
2
3
  import { Assertion } from "./types.js";
3
4
  import { InMemoryCredentialsHandler } from "./in-memory-credentials-handler.js";
@@ -16,6 +17,7 @@ export const KREIVO_AUTHORITY_ID = Binary.fromText("kreivo_p".padEnd(32, "\0"));
16
17
  export class WebAuthn {
17
18
  userId;
18
19
  getChallenge;
20
+ addressGenerator;
19
21
  /**
20
22
  * SHA‑256 hash of {@link userId}. Filled once by {@link setup} and reused
21
23
  * for all WebAuthn operations.
@@ -32,9 +34,10 @@ export class WebAuthn {
32
34
  * @param credentialsHandler - An implementation of {@link CredentialsHandler},
33
35
  *
34
36
  */
35
- constructor(userId, getChallenge, { publicKeyCreateOptions, publicKeyRequestOptions, onCreatedCredentials, } = new InMemoryCredentialsHandler()) {
37
+ constructor(userId, getChallenge, addressGenerator = kreivoPassDefaultAddressGenerator, { publicKeyCreateOptions, publicKeyRequestOptions, onCreatedCredentials, } = new InMemoryCredentialsHandler()) {
36
38
  this.userId = userId;
37
39
  this.getChallenge = getChallenge;
40
+ this.addressGenerator = addressGenerator;
38
41
  this.getPublicKeyCreateOptions = publicKeyCreateOptions;
39
42
  this.getPublicKeyRequestOptions = publicKeyRequestOptions;
40
43
  this.onCreatedCredentials = onCreatedCredentials;
@@ -74,7 +77,7 @@ export class WebAuthn {
74
77
  * @returns {Promise<TAttestation<number>>} SCALE‑encoded attestation object.
75
78
  */
76
79
  async register(blockNumber, displayName = this.userId) {
77
- const challenge = await this.getChallenge(blockNumber, new Uint8Array([]));
80
+ const challenge = await this.getChallenge(blockNumber, this.addressGenerator(this.hashedUserId));
78
81
  const credentials = (await navigator.credentials.create({
79
82
  publicKey: await this.getPublicKeyCreateOptions(challenge, {
80
83
  id: this.hashedUserId,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@virtonetwork/authenticators-webauthn",
3
3
  "description": "An Authenticator compatible with KreivoPassSigner that uses the WebAuthn standard",
4
- "version": "1.0.8",
4
+ "version": "1.1.1",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -36,7 +36,7 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@simplewebauthn/server": "^13.1.1",
39
- "@virtonetwork/signer": "^1.0.14",
39
+ "@virtonetwork/signer": "^1.1.0",
40
40
  "nid-webauthn-emulator": "^0.2.4"
41
41
  },
42
42
  "devDependencies": {