@astrox/identity 0.0.16 → 0.0.24
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/package.json +2 -2
- package/lib/cjs/buffer.d.ts +0 -10
- package/lib/cjs/buffer.js +0 -21
- package/lib/cjs/buffer.js.map +0 -1
- package/lib/cjs/identity/delegation.d.ts +0 -131
- package/lib/cjs/identity/delegation.js +0 -244
- package/lib/cjs/identity/delegation.js.map +0 -1
- package/lib/cjs/identity/der.d.ts +0 -26
- package/lib/cjs/identity/der.js +0 -145
- package/lib/cjs/identity/der.js.map +0 -1
- package/lib/cjs/identity/ed25519.d.ts +0 -45
- package/lib/cjs/identity/ed25519.js +0 -134
- package/lib/cjs/identity/ed25519.js.map +0 -1
- package/lib/cjs/identity/webauthn.d.ts +0 -40
- package/lib/cjs/identity/webauthn.js +0 -205
- package/lib/cjs/identity/webauthn.js.map +0 -1
- package/lib/cjs/index.d.ts +0 -4
- package/lib/cjs/index.js +0 -17
- package/lib/cjs/index.js.map +0 -1
- package/lib/esm/buffer.d.ts +0 -10
- package/lib/esm/buffer.js +0 -16
- package/lib/esm/buffer.js.map +0 -1
- package/lib/esm/identity/delegation.d.ts +0 -131
- package/lib/esm/identity/delegation.js +0 -219
- package/lib/esm/identity/delegation.js.map +0 -1
- package/lib/esm/identity/der.d.ts +0 -35
- package/lib/esm/identity/der.js +0 -168
- package/lib/esm/identity/der.js.map +0 -1
- package/lib/esm/identity/ed25519.d.ts +0 -45
- package/lib/esm/identity/ed25519.js +0 -110
- package/lib/esm/identity/ed25519.js.map +0 -1
- package/lib/esm/identity/secp256k1.d.ts +0 -73
- package/lib/esm/identity/secp256k1.js +0 -148
- package/lib/esm/identity/secp256k1.js.map +0 -1
- package/lib/esm/identity/webauthn.d.ts +0 -40
- package/lib/esm/identity/webauthn.js +0 -178
- package/lib/esm/identity/webauthn.js.map +0 -1
- package/lib/esm/index.d.ts +0 -4
- package/lib/esm/index.js +0 -5
- package/lib/esm/index.js.map +0 -1
- package/lib/tsconfig-cjs.tsbuildinfo +0 -1744
- package/lib/tsconfig.tsbuildinfo +0 -2508
@@ -1,73 +0,0 @@
|
|
1
|
-
import { DerEncodedPublicKey, KeyPair, Signature } from '@astrox/agent';
|
2
|
-
import { PublicKey, SignIdentity } from '@astrox/agent';
|
3
|
-
declare type PublicKeyHex = string;
|
4
|
-
declare type SecretKeyHex = string;
|
5
|
-
export declare type JsonableSecp256k1Identity = [PublicKeyHex, SecretKeyHex];
|
6
|
-
export declare class Secp256k1PublicKey implements PublicKey {
|
7
|
-
/**
|
8
|
-
* Construct Secp256k1PublicKey from an existing PublicKey
|
9
|
-
* @param {PublicKey} key
|
10
|
-
* @returns {Secp256k1PublicKey} Instance of Secp256k1PublicKey
|
11
|
-
*/
|
12
|
-
static from(key: PublicKey): Secp256k1PublicKey;
|
13
|
-
static fromRaw(rawKey: ArrayBuffer): Secp256k1PublicKey;
|
14
|
-
static fromDer(derKey: DerEncodedPublicKey): Secp256k1PublicKey;
|
15
|
-
private static derEncode;
|
16
|
-
private static derDecode;
|
17
|
-
private readonly rawKey;
|
18
|
-
private readonly derKey;
|
19
|
-
private constructor();
|
20
|
-
toDer(): DerEncodedPublicKey;
|
21
|
-
toRaw(): ArrayBuffer;
|
22
|
-
}
|
23
|
-
export declare class Secp256k1KeyIdentity extends SignIdentity {
|
24
|
-
protected _privateKey: ArrayBuffer;
|
25
|
-
/**
|
26
|
-
* Generates an identity. If a seed is provided, the keys are generated from the
|
27
|
-
* seed according to BIP 0032. Otherwise, the key pair is randomly generated.
|
28
|
-
* This method throws an error in case the seed is not 32 bytes long or invalid
|
29
|
-
* for use as a private key.
|
30
|
-
* @param {Uint8Array} seed the optional seed
|
31
|
-
* @returns {Secp256k1KeyIdentity}
|
32
|
-
*/
|
33
|
-
static generate(seed?: Uint8Array): Secp256k1KeyIdentity;
|
34
|
-
static fromParsedJson(obj: JsonableSecp256k1Identity): Secp256k1KeyIdentity;
|
35
|
-
static fromJSON(json: string): Secp256k1KeyIdentity;
|
36
|
-
/**
|
37
|
-
* generates an identity from a public and private key. Please ensure that you are generating these keys securely and protect the user's private key
|
38
|
-
* @param {ArrayBuffer} publicKey
|
39
|
-
* @param {ArrayBuffer} privateKey
|
40
|
-
* @returns {Secp256k1KeyIdentity}
|
41
|
-
*/
|
42
|
-
static fromKeyPair(publicKey: ArrayBuffer, privateKey: ArrayBuffer): Secp256k1KeyIdentity;
|
43
|
-
/**
|
44
|
-
* generates an identity from an existing secret key, and is the correct method to generate an identity from a seed phrase. Please ensure you protect the user's private key.
|
45
|
-
* @param {ArrayBuffer} secretKey
|
46
|
-
* @returns {Secp256k1KeyIdentity}
|
47
|
-
*/
|
48
|
-
static fromSecretKey(secretKey: ArrayBuffer): Secp256k1KeyIdentity;
|
49
|
-
protected _publicKey: Secp256k1PublicKey;
|
50
|
-
protected constructor(publicKey: Secp256k1PublicKey, _privateKey: ArrayBuffer);
|
51
|
-
/**
|
52
|
-
* Serialize this key to JSON-serializable object.
|
53
|
-
* @returns {JsonableSecp256k1Identity}
|
54
|
-
*/
|
55
|
-
toJSON(): JsonableSecp256k1Identity;
|
56
|
-
/**
|
57
|
-
* Return a copy of the key pair.
|
58
|
-
* @returns {KeyPair}
|
59
|
-
*/
|
60
|
-
getKeyPair(): KeyPair;
|
61
|
-
/**
|
62
|
-
* Return the public key.
|
63
|
-
* @returns {Secp256k1PublicKey}
|
64
|
-
*/
|
65
|
-
getPublicKey(): Secp256k1PublicKey;
|
66
|
-
/**
|
67
|
-
* Signs a blob of data, with this identity's private key.
|
68
|
-
* @param {ArrayBuffer} challenge - challenge to sign with this identity's secretKey, producing a signature
|
69
|
-
* @returns {Promise<Signature>} signature
|
70
|
-
*/
|
71
|
-
sign(challenge: ArrayBuffer): Promise<Signature>;
|
72
|
-
}
|
73
|
-
export default Secp256k1KeyIdentity;
|
@@ -1,148 +0,0 @@
|
|
1
|
-
import { SignIdentity } from '@astrox/agent';
|
2
|
-
import { sha256 } from 'js-sha256';
|
3
|
-
import Secp256k1 from 'secp256k1';
|
4
|
-
import { randomBytes } from 'tweetnacl';
|
5
|
-
import { fromHexString, toHexString } from '../buffer';
|
6
|
-
import { SECP256K1_OID, unwrapDER, wrapDER } from './der';
|
7
|
-
export class Secp256k1PublicKey {
|
8
|
-
// `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
|
9
|
-
constructor(key) {
|
10
|
-
key.byteLength;
|
11
|
-
this.rawKey = key;
|
12
|
-
this.derKey = Secp256k1PublicKey.derEncode(key);
|
13
|
-
}
|
14
|
-
/**
|
15
|
-
* Construct Secp256k1PublicKey from an existing PublicKey
|
16
|
-
* @param {PublicKey} key
|
17
|
-
* @returns {Secp256k1PublicKey} Instance of Secp256k1PublicKey
|
18
|
-
*/
|
19
|
-
static from(key) {
|
20
|
-
return this.fromDer(key.toDer());
|
21
|
-
}
|
22
|
-
static fromRaw(rawKey) {
|
23
|
-
return new Secp256k1PublicKey(rawKey);
|
24
|
-
}
|
25
|
-
static fromDer(derKey) {
|
26
|
-
return new Secp256k1PublicKey(this.derDecode(derKey));
|
27
|
-
}
|
28
|
-
static derEncode(publicKey) {
|
29
|
-
return wrapDER(publicKey, SECP256K1_OID).buffer;
|
30
|
-
}
|
31
|
-
static derDecode(key) {
|
32
|
-
return unwrapDER(key, SECP256K1_OID);
|
33
|
-
}
|
34
|
-
toDer() {
|
35
|
-
return this.derKey;
|
36
|
-
}
|
37
|
-
toRaw() {
|
38
|
-
return this.rawKey;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
export class Secp256k1KeyIdentity extends SignIdentity {
|
42
|
-
constructor(publicKey, _privateKey) {
|
43
|
-
super();
|
44
|
-
this._privateKey = _privateKey;
|
45
|
-
this._publicKey = publicKey;
|
46
|
-
}
|
47
|
-
/**
|
48
|
-
* Generates an identity. If a seed is provided, the keys are generated from the
|
49
|
-
* seed according to BIP 0032. Otherwise, the key pair is randomly generated.
|
50
|
-
* This method throws an error in case the seed is not 32 bytes long or invalid
|
51
|
-
* for use as a private key.
|
52
|
-
* @param {Uint8Array} seed the optional seed
|
53
|
-
* @returns {Secp256k1KeyIdentity}
|
54
|
-
*/
|
55
|
-
static generate(seed) {
|
56
|
-
if (seed && seed.byteLength !== 32) {
|
57
|
-
throw new Error('Secp256k1 Seed needs to be 32 bytes long.');
|
58
|
-
}
|
59
|
-
let privateKey;
|
60
|
-
if (seed) {
|
61
|
-
// private key from seed according to https://en.bitcoin.it/wiki/BIP_0032
|
62
|
-
// master key generation:
|
63
|
-
privateKey = seed;
|
64
|
-
if (!Secp256k1.privateKeyVerify(privateKey)) {
|
65
|
-
throw new Error('The seed is invalid.');
|
66
|
-
}
|
67
|
-
}
|
68
|
-
else {
|
69
|
-
privateKey = new Uint8Array(randomBytes(32));
|
70
|
-
while (!Secp256k1.privateKeyVerify(privateKey)) {
|
71
|
-
privateKey = new Uint8Array(randomBytes(32));
|
72
|
-
}
|
73
|
-
}
|
74
|
-
const publicKeyRaw = Secp256k1.publicKeyCreate(privateKey, false);
|
75
|
-
const publicKey = Secp256k1PublicKey.fromRaw(publicKeyRaw);
|
76
|
-
return new this(publicKey, privateKey);
|
77
|
-
}
|
78
|
-
static fromParsedJson(obj) {
|
79
|
-
const [publicKeyRaw, privateKeyRaw] = obj;
|
80
|
-
return new Secp256k1KeyIdentity(Secp256k1PublicKey.fromRaw(fromHexString(publicKeyRaw)), fromHexString(privateKeyRaw));
|
81
|
-
}
|
82
|
-
static fromJSON(json) {
|
83
|
-
const parsed = JSON.parse(json);
|
84
|
-
if (Array.isArray(parsed)) {
|
85
|
-
if (typeof parsed[0] === 'string' && typeof parsed[1] === 'string') {
|
86
|
-
return this.fromParsedJson([parsed[0], parsed[1]]);
|
87
|
-
}
|
88
|
-
throw new Error('Deserialization error: JSON must have at least 2 items.');
|
89
|
-
}
|
90
|
-
throw new Error(`Deserialization error: Invalid JSON type for string: ${JSON.stringify(json)}`);
|
91
|
-
}
|
92
|
-
/**
|
93
|
-
* generates an identity from a public and private key. Please ensure that you are generating these keys securely and protect the user's private key
|
94
|
-
* @param {ArrayBuffer} publicKey
|
95
|
-
* @param {ArrayBuffer} privateKey
|
96
|
-
* @returns {Secp256k1KeyIdentity}
|
97
|
-
*/
|
98
|
-
static fromKeyPair(publicKey, privateKey) {
|
99
|
-
return new Secp256k1KeyIdentity(Secp256k1PublicKey.fromRaw(publicKey), privateKey);
|
100
|
-
}
|
101
|
-
/**
|
102
|
-
* generates an identity from an existing secret key, and is the correct method to generate an identity from a seed phrase. Please ensure you protect the user's private key.
|
103
|
-
* @param {ArrayBuffer} secretKey
|
104
|
-
* @returns {Secp256k1KeyIdentity}
|
105
|
-
*/
|
106
|
-
static fromSecretKey(secretKey) {
|
107
|
-
const publicKey = Secp256k1.publicKeyCreate(new Uint8Array(secretKey), false);
|
108
|
-
const identity = Secp256k1KeyIdentity.fromKeyPair(publicKey, new Uint8Array(secretKey));
|
109
|
-
return identity;
|
110
|
-
}
|
111
|
-
/**
|
112
|
-
* Serialize this key to JSON-serializable object.
|
113
|
-
* @returns {JsonableSecp256k1Identity}
|
114
|
-
*/
|
115
|
-
toJSON() {
|
116
|
-
return [toHexString(this._publicKey.toRaw()), toHexString(this._privateKey)];
|
117
|
-
}
|
118
|
-
/**
|
119
|
-
* Return a copy of the key pair.
|
120
|
-
* @returns {KeyPair}
|
121
|
-
*/
|
122
|
-
getKeyPair() {
|
123
|
-
return {
|
124
|
-
secretKey: this._privateKey,
|
125
|
-
publicKey: this._publicKey,
|
126
|
-
};
|
127
|
-
}
|
128
|
-
/**
|
129
|
-
* Return the public key.
|
130
|
-
* @returns {Secp256k1PublicKey}
|
131
|
-
*/
|
132
|
-
getPublicKey() {
|
133
|
-
return this._publicKey;
|
134
|
-
}
|
135
|
-
/**
|
136
|
-
* Signs a blob of data, with this identity's private key.
|
137
|
-
* @param {ArrayBuffer} challenge - challenge to sign with this identity's secretKey, producing a signature
|
138
|
-
* @returns {Promise<Signature>} signature
|
139
|
-
*/
|
140
|
-
async sign(challenge) {
|
141
|
-
const hash = sha256.create();
|
142
|
-
hash.update(challenge);
|
143
|
-
const signature = Secp256k1.ecdsaSign(new Uint8Array(hash.digest()), new Uint8Array(this._privateKey)).signature.buffer;
|
144
|
-
return signature;
|
145
|
-
}
|
146
|
-
}
|
147
|
-
export default Secp256k1KeyIdentity;
|
148
|
-
//# sourceMappingURL=secp256k1.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["../../../src/identity/secp256k1.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,YAAY,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAM1D,MAAM,OAAO,kBAAkB;IA8B7B,kFAAkF;IAClF,YAAoB,GAAgB;QAClC,GAAG,CAAC,UAAU,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,kBAAkB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAClD,CAAC;IAlCD;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,GAAc;QAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;IACnC,CAAC;IAEM,MAAM,CAAC,OAAO,CAAC,MAAmB;QACvC,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAEM,MAAM,CAAC,OAAO,CAAC,MAA2B;QAC/C,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC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IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;QAC9E,MAAM,QAAQ,GAAG,oBAAoB,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;QACxF,OAAO,QAAQ,CAAC;IAClB,CAAC;IASD;;;OAGG;IACI,MAAM;QACX,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED;;;OAGG;IACI,UAAU;QACf,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,WAAW;YAC3B,SAAS,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,YAAY;QACjB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,IAAI,CAAC,SAAsB;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACvB,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CACnC,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAC7B,IAAI,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CACjC,CAAC,SAAS,CAAC,MAAM,CAAC;QACnB,OAAO,SAAsB,CAAC;IAChC,CAAC;CACF;AAED,eAAe,oBAAoB,CAAC"}
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import { DerEncodedPublicKey, PublicKey, Signature, SignIdentity } from '@astrox/agent';
|
2
|
-
export declare class CosePublicKey implements PublicKey {
|
3
|
-
protected _cose: ArrayBuffer;
|
4
|
-
protected _encodedKey: DerEncodedPublicKey;
|
5
|
-
constructor(_cose: ArrayBuffer);
|
6
|
-
toDer(): DerEncodedPublicKey;
|
7
|
-
getCose(): ArrayBuffer;
|
8
|
-
}
|
9
|
-
/**
|
10
|
-
* A SignIdentity that uses `navigator.credentials`. See https://webauthn.guide/ for
|
11
|
-
* more information about WebAuthentication.
|
12
|
-
*/
|
13
|
-
export declare class WebAuthnIdentity extends SignIdentity {
|
14
|
-
readonly rawId: ArrayBuffer;
|
15
|
-
/**
|
16
|
-
* Create an identity from a JSON serialization.
|
17
|
-
* @param json - json to parse
|
18
|
-
*/
|
19
|
-
static fromJSON(json: string): WebAuthnIdentity;
|
20
|
-
/**
|
21
|
-
* Create an identity.
|
22
|
-
* @param credentialCreationOptions an optional CredentialCreationOptions Challenge
|
23
|
-
*/
|
24
|
-
static create(credentialCreationOptions?: CredentialCreationOptions): Promise<WebAuthnIdentity>;
|
25
|
-
protected _publicKey: CosePublicKey;
|
26
|
-
protected constructor(rawId: ArrayBuffer, cose: ArrayBuffer);
|
27
|
-
getPublicKey(): PublicKey;
|
28
|
-
sign(blob: ArrayBuffer): Promise<Signature>;
|
29
|
-
/**
|
30
|
-
* Allow for JSON serialization of all information needed to reuse this identity.
|
31
|
-
*/
|
32
|
-
toJSON(): JsonnableWebAuthnIdentitiy;
|
33
|
-
}
|
34
|
-
/**
|
35
|
-
* ReturnType<WebAuthnIdentity.toJSON>
|
36
|
-
*/
|
37
|
-
export interface JsonnableWebAuthnIdentitiy {
|
38
|
-
publicKey: string;
|
39
|
-
rawId: string;
|
40
|
-
}
|
@@ -1,178 +0,0 @@
|
|
1
|
-
import { SignIdentity } from '@astrox/agent';
|
2
|
-
import borc from 'borc';
|
3
|
-
import * as tweetnacl from 'tweetnacl';
|
4
|
-
import { fromHexString, toHexString } from '../buffer';
|
5
|
-
import { DER_COSE_OID, wrapDER } from './der';
|
6
|
-
function _coseToDerEncodedBlob(cose) {
|
7
|
-
return wrapDER(cose, DER_COSE_OID).buffer;
|
8
|
-
}
|
9
|
-
/**
|
10
|
-
* From the documentation;
|
11
|
-
* The authData is a byte array described in the spec. Parsing it will involve slicing bytes from
|
12
|
-
* the array and converting them into usable objects.
|
13
|
-
*
|
14
|
-
* See https://webauthn.guide/#registration (subsection "Example: Parsing the authenticator data").
|
15
|
-
*
|
16
|
-
* @param authData The authData field of the attestation response.
|
17
|
-
* @returns The COSE key of the authData.
|
18
|
-
*/
|
19
|
-
function _authDataToCose(authData) {
|
20
|
-
const dataView = new DataView(new ArrayBuffer(2));
|
21
|
-
const idLenBytes = authData.slice(53, 55);
|
22
|
-
[...new Uint8Array(idLenBytes)].forEach((v, i) => dataView.setUint8(i, v));
|
23
|
-
const credentialIdLength = dataView.getUint16(0);
|
24
|
-
// Get the public key object.
|
25
|
-
return authData.slice(55 + credentialIdLength);
|
26
|
-
}
|
27
|
-
export class CosePublicKey {
|
28
|
-
constructor(_cose) {
|
29
|
-
this._cose = _cose;
|
30
|
-
this._encodedKey = _coseToDerEncodedBlob(_cose);
|
31
|
-
}
|
32
|
-
toDer() {
|
33
|
-
return this._encodedKey;
|
34
|
-
}
|
35
|
-
getCose() {
|
36
|
-
return this._cose;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
/**
|
40
|
-
* Create a challenge from a string or array. The default challenge is always the same
|
41
|
-
* because we don't need to verify the authenticity of the key on the server (we don't
|
42
|
-
* register our keys with the IC). Any challenge would do, even one per key, randomly
|
43
|
-
* generated.
|
44
|
-
*
|
45
|
-
* @param challenge The challenge to transform into a byte array. By default a hard
|
46
|
-
* coded string.
|
47
|
-
*/
|
48
|
-
function _createChallengeBuffer(challenge = '<ic0.app>') {
|
49
|
-
if (typeof challenge === 'string') {
|
50
|
-
return Uint8Array.from(challenge, c => c.charCodeAt(0));
|
51
|
-
}
|
52
|
-
else {
|
53
|
-
return challenge;
|
54
|
-
}
|
55
|
-
}
|
56
|
-
/**
|
57
|
-
* Create a credentials to authenticate with a server. This is necessary in order in
|
58
|
-
* WebAuthn to get credentials IDs (which give us the public key and allow us to
|
59
|
-
* sign), but in the case of the Internet Computer, we don't actually need to register
|
60
|
-
* it, so we don't.
|
61
|
-
* @param credentialCreationOptions an optional CredentialCreationOptions object
|
62
|
-
*/
|
63
|
-
async function _createCredential(credentialCreationOptions) {
|
64
|
-
const creds = (await navigator.credentials.create(credentialCreationOptions !== null && credentialCreationOptions !== void 0 ? credentialCreationOptions : {
|
65
|
-
publicKey: {
|
66
|
-
authenticatorSelection: {
|
67
|
-
userVerification: 'preferred',
|
68
|
-
},
|
69
|
-
attestation: 'direct',
|
70
|
-
challenge: _createChallengeBuffer(),
|
71
|
-
pubKeyCredParams: [{ type: 'public-key', alg: PubKeyCoseAlgo.ECDSA_WITH_SHA256 }],
|
72
|
-
rp: {
|
73
|
-
name: 'Internet Identity Service',
|
74
|
-
},
|
75
|
-
user: {
|
76
|
-
id: tweetnacl.randomBytes(16),
|
77
|
-
name: 'Internet Identity',
|
78
|
-
displayName: 'Internet Identity',
|
79
|
-
},
|
80
|
-
},
|
81
|
-
}));
|
82
|
-
// Validate that it's the correct type at runtime, since WebAuthn does not HAVE to
|
83
|
-
// reply with a PublicKeyCredential.
|
84
|
-
if (creds.response === undefined || !(creds.rawId instanceof ArrayBuffer)) {
|
85
|
-
return null;
|
86
|
-
}
|
87
|
-
else {
|
88
|
-
return creds;
|
89
|
-
}
|
90
|
-
}
|
91
|
-
// See https://www.iana.org/assignments/cose/cose.xhtml#algorithms for a complete
|
92
|
-
// list of these algorithms. We only list the ones we support here.
|
93
|
-
var PubKeyCoseAlgo;
|
94
|
-
(function (PubKeyCoseAlgo) {
|
95
|
-
PubKeyCoseAlgo[PubKeyCoseAlgo["ECDSA_WITH_SHA256"] = -7] = "ECDSA_WITH_SHA256";
|
96
|
-
})(PubKeyCoseAlgo || (PubKeyCoseAlgo = {}));
|
97
|
-
/**
|
98
|
-
* A SignIdentity that uses `navigator.credentials`. See https://webauthn.guide/ for
|
99
|
-
* more information about WebAuthentication.
|
100
|
-
*/
|
101
|
-
export class WebAuthnIdentity extends SignIdentity {
|
102
|
-
constructor(rawId, cose) {
|
103
|
-
super();
|
104
|
-
this.rawId = rawId;
|
105
|
-
this._publicKey = new CosePublicKey(cose);
|
106
|
-
}
|
107
|
-
/**
|
108
|
-
* Create an identity from a JSON serialization.
|
109
|
-
* @param json - json to parse
|
110
|
-
*/
|
111
|
-
static fromJSON(json) {
|
112
|
-
const { publicKey, rawId } = JSON.parse(json);
|
113
|
-
if (typeof publicKey !== 'string' || typeof rawId !== 'string') {
|
114
|
-
throw new Error('Invalid JSON string.');
|
115
|
-
}
|
116
|
-
return new this(fromHexString(rawId), fromHexString(publicKey));
|
117
|
-
}
|
118
|
-
/**
|
119
|
-
* Create an identity.
|
120
|
-
* @param credentialCreationOptions an optional CredentialCreationOptions Challenge
|
121
|
-
*/
|
122
|
-
static async create(credentialCreationOptions) {
|
123
|
-
const creds = await _createCredential(credentialCreationOptions);
|
124
|
-
if (!creds || creds.type !== 'public-key') {
|
125
|
-
throw new Error('Could not create credentials.');
|
126
|
-
}
|
127
|
-
const response = creds.response;
|
128
|
-
if (!(response.attestationObject instanceof ArrayBuffer)) {
|
129
|
-
throw new Error('Was expecting an attestation response.');
|
130
|
-
}
|
131
|
-
// Parse the attestationObject as CBOR.
|
132
|
-
const attObject = borc.decodeFirst(new Uint8Array(response.attestationObject));
|
133
|
-
return new this(creds.rawId, _authDataToCose(attObject.authData));
|
134
|
-
}
|
135
|
-
getPublicKey() {
|
136
|
-
return this._publicKey;
|
137
|
-
}
|
138
|
-
async sign(blob) {
|
139
|
-
const result = (await navigator.credentials.get({
|
140
|
-
publicKey: {
|
141
|
-
allowCredentials: [
|
142
|
-
{
|
143
|
-
type: 'public-key',
|
144
|
-
id: this.rawId,
|
145
|
-
},
|
146
|
-
],
|
147
|
-
challenge: blob,
|
148
|
-
userVerification: 'preferred',
|
149
|
-
},
|
150
|
-
}));
|
151
|
-
const response = result.response;
|
152
|
-
if (response.signature instanceof ArrayBuffer &&
|
153
|
-
response.authenticatorData instanceof ArrayBuffer) {
|
154
|
-
const cbor = borc.encode(new borc.Tagged(55799, {
|
155
|
-
authenticator_data: new Uint8Array(response.authenticatorData),
|
156
|
-
client_data_json: new TextDecoder().decode(response.clientDataJSON),
|
157
|
-
signature: new Uint8Array(response.signature),
|
158
|
-
}));
|
159
|
-
if (!cbor) {
|
160
|
-
throw new Error('failed to encode cbor');
|
161
|
-
}
|
162
|
-
return cbor.buffer;
|
163
|
-
}
|
164
|
-
else {
|
165
|
-
throw new Error('Invalid response from WebAuthn.');
|
166
|
-
}
|
167
|
-
}
|
168
|
-
/**
|
169
|
-
* Allow for JSON serialization of all information needed to reuse this identity.
|
170
|
-
*/
|
171
|
-
toJSON() {
|
172
|
-
return {
|
173
|
-
publicKey: toHexString(this._publicKey.getCose()),
|
174
|
-
rawId: toHexString(this.rawId),
|
175
|
-
};
|
176
|
-
}
|
177
|
-
}
|
178
|
-
//# sourceMappingURL=webauthn.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"webauthn.js","sourceRoot":"","sources":["../../../src/identity/webauthn.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,YAAY,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE9C,SAAS,qBAAqB,CAAC,IAAiB;IAC9C,OAAO,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,MAA6B,CAAC;AACnE,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,QAAqB;IAC5C,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC,GAAG,IAAI,UAAU,CAAC,UAA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EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,iBAAiB,CAAC;gBAC9D,gBAAgB,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC;gBACnE,SAAS,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC;aAC9C,CAAC,CACH,CAAC;YACF,IAAI,CAAC,IAAI,EAAE;gBACT,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;aAC1C;YACD,OAAO,IAAI,CAAC,MAAmB,CAAC;SACjC;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;SACpD;IACH,CAAC;IAED;;OAEG;IACI,MAAM;QACX,OAAO;YACL,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YACjD,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC;SAC/B,CAAC;IACJ,CAAC;CACF"}
|
package/lib/esm/index.d.ts
DELETED
@@ -1,4 +0,0 @@
|
|
1
|
-
export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519';
|
2
|
-
export { Delegation, DelegationIdentity, DelegationChain, SignedDelegation, } from './identity/delegation';
|
3
|
-
export { WebAuthnIdentity } from './identity/webauthn';
|
4
|
-
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der';
|
package/lib/esm/index.js
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
export { Ed25519KeyIdentity, Ed25519PublicKey } from './identity/ed25519';
|
2
|
-
export { Delegation, DelegationIdentity, DelegationChain, } from './identity/delegation';
|
3
|
-
export { WebAuthnIdentity } from './identity/webauthn';
|
4
|
-
export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from './identity/der';
|
5
|
-
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,eAAe,GAEhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|