@dwn-protocol/id-sdk 0.2.5 → 0.2.6
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 -3
- package/src/agent/app-data-store.ts +0 -365
- package/src/agent/did-manager.ts +0 -393
- package/src/agent/dwn-manager.ts +0 -548
- package/src/agent/identity-manager.ts +0 -165
- package/src/agent/index.ts +0 -19
- package/src/agent/json-rpc.ts +0 -107
- package/src/agent/key-manager.ts +0 -302
- package/src/agent/kms-local.ts +0 -412
- package/src/agent/outbox.ts +0 -128
- package/src/agent/rpc-client.ts +0 -223
- package/src/agent/store-managed-did.ts +0 -295
- package/src/agent/store-managed-identity.ts +0 -243
- package/src/agent/store-managed-key.ts +0 -754
- package/src/agent/sync-manager.ts +0 -631
- package/src/agent/test-managed-agent.ts +0 -299
- package/src/agent/types/agent.ts +0 -145
- package/src/agent/types/managed-key.ts +0 -442
- package/src/agent/utils.ts +0 -190
- package/src/common/convert.ts +0 -424
- package/src/common/index.ts +0 -9
- package/src/common/multicodec.ts +0 -176
- package/src/common/object.ts +0 -43
- package/src/common/stores.ts +0 -125
- package/src/common/stream-node.ts +0 -381
- package/src/common/stream.ts +0 -406
- package/src/common/type-utils.ts +0 -117
- package/src/common/types.ts +0 -48
- package/src/credentials/credential-bbs.ts +0 -419
- package/src/credentials/credential.ts +0 -324
- package/src/credentials/index.ts +0 -5
- package/src/credentials/presentation.ts +0 -182
- package/src/credentials/status-list.ts +0 -365
- package/src/credentials/utils.ts +0 -58
- package/src/credentials/validators.ts +0 -52
- package/src/crypto/algorithms-api/aes/base.ts +0 -49
- package/src/crypto/algorithms-api/aes/ctr.ts +0 -51
- package/src/crypto/algorithms-api/aes/index.ts +0 -2
- package/src/crypto/algorithms-api/crypto-algorithm.ts +0 -127
- package/src/crypto/algorithms-api/crypto-key.ts +0 -56
- package/src/crypto/algorithms-api/ec/base.ts +0 -39
- package/src/crypto/algorithms-api/ec/ecdh.ts +0 -53
- package/src/crypto/algorithms-api/ec/ecdsa.ts +0 -37
- package/src/crypto/algorithms-api/ec/eddsa.ts +0 -30
- package/src/crypto/algorithms-api/ec/index.ts +0 -4
- package/src/crypto/algorithms-api/errors.ts +0 -29
- package/src/crypto/algorithms-api/index.ts +0 -6
- package/src/crypto/algorithms-api/pbkdf/index.ts +0 -1
- package/src/crypto/algorithms-api/pbkdf/pbkdf2.ts +0 -91
- package/src/crypto/crypto-algorithms/aes-ctr.ts +0 -70
- package/src/crypto/crypto-algorithms/bbs.ts +0 -110
- package/src/crypto/crypto-algorithms/ecdh.ts +0 -115
- package/src/crypto/crypto-algorithms/ecdsa.ts +0 -111
- package/src/crypto/crypto-algorithms/eddsa.ts +0 -110
- package/src/crypto/crypto-algorithms/index.ts +0 -6
- package/src/crypto/crypto-algorithms/pbkdf2.ts +0 -54
- package/src/crypto/crypto-primitives/aes-ctr.ts +0 -131
- package/src/crypto/crypto-primitives/aes-gcm.ts +0 -138
- package/src/crypto/crypto-primitives/bbs.ts +0 -183
- package/src/crypto/crypto-primitives/concat-kdf.ts +0 -207
- package/src/crypto/crypto-primitives/ed25519.ts +0 -201
- package/src/crypto/crypto-primitives/index.ts +0 -10
- package/src/crypto/crypto-primitives/pbkdf2.ts +0 -78
- package/src/crypto/crypto-primitives/secp256k1.ts +0 -322
- package/src/crypto/crypto-primitives/x25519.ts +0 -101
- package/src/crypto/crypto-primitives/xchacha20-poly1305.ts +0 -46
- package/src/crypto/crypto-primitives/xchacha20.ts +0 -34
- package/src/crypto/index.ts +0 -8
- package/src/crypto/jose.ts +0 -948
- package/src/crypto/types/crypto-key.ts +0 -4
- package/src/crypto/types/iddwn-crypto.ts +0 -119
- package/src/crypto/utils.ts +0 -200
- package/src/did-api.ts +0 -72
- package/src/dids/dht.ts +0 -412
- package/src/dids/did-dht.ts +0 -436
- package/src/dids/did-ion.ts +0 -613
- package/src/dids/did-key.ts +0 -791
- package/src/dids/did-resolver.ts +0 -107
- package/src/dids/index.ts +0 -9
- package/src/dids/resolver-cache-level.ts +0 -82
- package/src/dids/resolver-cache-noop.ts +0 -25
- package/src/dids/types.ts +0 -278
- package/src/dids/utils.ts +0 -129
- package/src/dwn-api.ts +0 -584
- package/src/iddwn.ts +0 -241
- package/src/identity-agent/index.ts +0 -270
- package/src/index.ts +0 -26
- package/src/interfaces/metadata.ts +0 -163
- package/src/interfaces/queue.ts +0 -108
- package/src/interfaces/services.ts +0 -122
- package/src/interfaces/transactions.ts +0 -220
- package/src/protocol.ts +0 -68
- package/src/proxy-agent/index.ts +0 -255
- package/src/record.ts +0 -521
- package/src/service-options.ts +0 -62
- package/src/typings/decentralized-identity__ion-pow-sdk.d.ts +0 -7
- package/src/user-agent/index.ts +0 -295
- package/src/utils.ts +0 -29
- package/src/vc-api.ts +0 -505
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import type { IDCrypto } from '../types/iddwn-crypto.js';
|
|
2
|
-
|
|
3
|
-
import { InvalidAccessError, NotSupportedError } from './errors.js';
|
|
4
|
-
|
|
5
|
-
export abstract class CryptoAlgorithm {
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Name of the algorithm
|
|
9
|
-
*/
|
|
10
|
-
public abstract readonly name: string;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Indicates which cryptographic operations are permissible to be used with this algorithm.
|
|
14
|
-
*/
|
|
15
|
-
public abstract readonly keyUsages: IDCrypto.KeyUsage[] | IDCrypto.KeyPairUsage;
|
|
16
|
-
|
|
17
|
-
public checkAlgorithmName(options: {
|
|
18
|
-
algorithmName: string
|
|
19
|
-
}): void {
|
|
20
|
-
const { algorithmName } = options;
|
|
21
|
-
if (algorithmName === undefined) {
|
|
22
|
-
throw new TypeError(`Required parameter missing: 'algorithmName'`);
|
|
23
|
-
}
|
|
24
|
-
if (algorithmName !== this.name) {
|
|
25
|
-
throw new NotSupportedError(`Algorithm not supported: '${algorithmName}'`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public checkCryptoKey(options: {
|
|
30
|
-
key: IDCrypto.CryptoKey
|
|
31
|
-
}): void {
|
|
32
|
-
const { key } = options;
|
|
33
|
-
if (!('algorithm' in key && 'extractable' in key && 'type' in key && 'usages' in key)) {
|
|
34
|
-
throw new TypeError('Object is not a CryptoKey');
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public checkKeyAlgorithm(options: {
|
|
39
|
-
keyAlgorithmName: string
|
|
40
|
-
}): void {
|
|
41
|
-
const { keyAlgorithmName } = options;
|
|
42
|
-
if (keyAlgorithmName === undefined) {
|
|
43
|
-
throw new TypeError(`Required parameter missing: 'keyAlgorithmName'`);
|
|
44
|
-
}
|
|
45
|
-
if (keyAlgorithmName && keyAlgorithmName !== this.name) {
|
|
46
|
-
throw new InvalidAccessError(`Algorithm '${this.name}' does not match the provided '${keyAlgorithmName}' key.`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public checkKeyType(options: {
|
|
51
|
-
keyType: IDCrypto.KeyType,
|
|
52
|
-
allowedKeyType: IDCrypto.KeyType
|
|
53
|
-
}): void {
|
|
54
|
-
const { keyType, allowedKeyType } = options;
|
|
55
|
-
if (keyType === undefined || allowedKeyType === undefined) {
|
|
56
|
-
throw new TypeError(`One or more required parameters missing: 'keyType, allowedKeyType'`);
|
|
57
|
-
}
|
|
58
|
-
if (keyType && keyType !== allowedKeyType) {
|
|
59
|
-
throw new InvalidAccessError(`Requested operation is not valid for the provided '${keyType}' key.`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public checkKeyUsages(options: {
|
|
64
|
-
keyUsages: IDCrypto.KeyUsage[],
|
|
65
|
-
allowedKeyUsages: IDCrypto.KeyUsage[] | IDCrypto.KeyPairUsage
|
|
66
|
-
}): void {
|
|
67
|
-
const { keyUsages, allowedKeyUsages } = options;
|
|
68
|
-
if (!(keyUsages && keyUsages.length > 0)) {
|
|
69
|
-
throw new TypeError(`Required parameter missing or empty: 'keyUsages'`);
|
|
70
|
-
}
|
|
71
|
-
const allowedUsages = (Array.isArray(allowedKeyUsages)) ? allowedKeyUsages : [...allowedKeyUsages.privateKey, ...allowedKeyUsages.publicKey];
|
|
72
|
-
if (!keyUsages.every(usage => allowedUsages.includes(usage))) {
|
|
73
|
-
throw new InvalidAccessError(`Requested operation(s) '${keyUsages.join(', ')}' is not valid for the provided key.`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Creates an instance of the class on which it is called.
|
|
79
|
-
*
|
|
80
|
-
* This is a generic factory method that creates an instance of any
|
|
81
|
-
* crypto algorithm that extends this abstract class.
|
|
82
|
-
*
|
|
83
|
-
* @template T The type of the instance to be created.
|
|
84
|
-
* @returns An instance of the class it is called on.
|
|
85
|
-
* @throws {TypeError} If the class it is called on cannot be constructed.
|
|
86
|
-
*/
|
|
87
|
-
static create<T extends CryptoAlgorithm>(this: new () => T): T {
|
|
88
|
-
return new this();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public abstract decrypt(options: {
|
|
92
|
-
algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.AesCtrOptions | IDCrypto.AesGcmOptions,
|
|
93
|
-
key: IDCrypto.CryptoKey,
|
|
94
|
-
data: Uint8Array
|
|
95
|
-
}): Promise<Uint8Array>;
|
|
96
|
-
|
|
97
|
-
public abstract deriveBits(options: {
|
|
98
|
-
algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.EcdhDeriveKeyOptions,
|
|
99
|
-
baseKey: IDCrypto.CryptoKey,
|
|
100
|
-
length: number | null
|
|
101
|
-
}): Promise<Uint8Array>;
|
|
102
|
-
|
|
103
|
-
public abstract encrypt(options: {
|
|
104
|
-
algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.AesCtrOptions | IDCrypto.AesGcmOptions,
|
|
105
|
-
key: IDCrypto.CryptoKey,
|
|
106
|
-
data: Uint8Array
|
|
107
|
-
}): Promise<Uint8Array>;
|
|
108
|
-
|
|
109
|
-
public abstract generateKey(options: {
|
|
110
|
-
algorithm: Partial<IDCrypto.GenerateKeyOptions>,
|
|
111
|
-
extractable: boolean,
|
|
112
|
-
keyUsages: IDCrypto.KeyUsage[],
|
|
113
|
-
}): Promise<IDCrypto.CryptoKey | IDCrypto.CryptoKeyPair>;
|
|
114
|
-
|
|
115
|
-
public abstract sign(options: {
|
|
116
|
-
algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.EcdsaOptions | IDCrypto.EdDsaOptions,
|
|
117
|
-
key: IDCrypto.CryptoKey,
|
|
118
|
-
data: Uint8Array
|
|
119
|
-
}): Promise<Uint8Array>;
|
|
120
|
-
|
|
121
|
-
public abstract verify(options: {
|
|
122
|
-
algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.EcdsaOptions | IDCrypto.EdDsaOptions,
|
|
123
|
-
key: IDCrypto.CryptoKey,
|
|
124
|
-
signature: Uint8Array,
|
|
125
|
-
data: Uint8Array
|
|
126
|
-
}): Promise<boolean>;
|
|
127
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { IDCrypto } from '../types/iddwn-crypto.js';
|
|
2
|
-
|
|
3
|
-
export class CryptoKey implements IDCrypto.CryptoKey {
|
|
4
|
-
public algorithm: IDCrypto.KeyAlgorithm | IDCrypto.GenerateKeyOptions;
|
|
5
|
-
public extractable: boolean;
|
|
6
|
-
public material: Uint8Array;
|
|
7
|
-
public type: IDCrypto.KeyType;
|
|
8
|
-
public usages: IDCrypto.KeyUsage[];
|
|
9
|
-
|
|
10
|
-
constructor (algorithm: IDCrypto.KeyAlgorithm | IDCrypto.GenerateKeyOptions, extractable: boolean, material: Uint8Array, type: IDCrypto.KeyType, usages: IDCrypto.KeyUsage[]) {
|
|
11
|
-
this.algorithm = algorithm;
|
|
12
|
-
this.extractable = extractable;
|
|
13
|
-
this.material = material;
|
|
14
|
-
this.type = type;
|
|
15
|
-
this.usages = usages;
|
|
16
|
-
|
|
17
|
-
// ensure values are not writeable
|
|
18
|
-
Object.defineProperties(this, {
|
|
19
|
-
// TODO
|
|
20
|
-
// These properties can't be fixed immediately on creation of the
|
|
21
|
-
// object because the implementation may build it up in stages.
|
|
22
|
-
// At some point in the operations before returning a key we should
|
|
23
|
-
// freeze the object to prevent further manipulation.
|
|
24
|
-
|
|
25
|
-
type: {
|
|
26
|
-
enumerable : true,
|
|
27
|
-
writable : false,
|
|
28
|
-
value : type
|
|
29
|
-
},
|
|
30
|
-
extractable: {
|
|
31
|
-
enumerable : true,
|
|
32
|
-
writable : true,
|
|
33
|
-
value : extractable
|
|
34
|
-
},
|
|
35
|
-
algorithm: {
|
|
36
|
-
enumerable : true,
|
|
37
|
-
writable : false,
|
|
38
|
-
value : algorithm
|
|
39
|
-
},
|
|
40
|
-
usages: {
|
|
41
|
-
enumerable : true,
|
|
42
|
-
writable : true,
|
|
43
|
-
value : usages
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
// this is the "key material" used internally
|
|
47
|
-
// it is not enumerable, but we need it to be
|
|
48
|
-
// accessible by algorithm implementations
|
|
49
|
-
material: {
|
|
50
|
-
enumerable : false,
|
|
51
|
-
writable : false,
|
|
52
|
-
value : material
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { IDCrypto } from '../../types/iddwn-crypto.js';
|
|
2
|
-
|
|
3
|
-
import { InvalidAccessError } from '../errors.js';
|
|
4
|
-
import { CryptoAlgorithm } from '../crypto-algorithm.js';
|
|
5
|
-
import { checkValidProperty, checkRequiredProperty } from '../../utils.js';
|
|
6
|
-
|
|
7
|
-
export abstract class BaseEllipticCurveAlgorithm extends CryptoAlgorithm {
|
|
8
|
-
|
|
9
|
-
public abstract namedCurves: string[];
|
|
10
|
-
|
|
11
|
-
public checkGenerateKey(options: {
|
|
12
|
-
algorithm: IDCrypto.EcGenerateKeyOptions,
|
|
13
|
-
keyUsages: IDCrypto.KeyUsage[]
|
|
14
|
-
}): void {
|
|
15
|
-
const { algorithm, keyUsages } = options;
|
|
16
|
-
// Algorithm specified in the operation must match the algorithm implementation processing the operation.
|
|
17
|
-
this.checkAlgorithmName({ algorithmName: algorithm.name });
|
|
18
|
-
// The algorithm object must contain a namedCurve property.
|
|
19
|
-
checkRequiredProperty({ property: 'namedCurve', inObject: algorithm });
|
|
20
|
-
// The named curve specified must be supported by the algorithm implementation processing the operation.
|
|
21
|
-
checkValidProperty({ property: algorithm.namedCurve, allowedProperties: this.namedCurves });
|
|
22
|
-
// The key usages specified must be permitted by the algorithm implementation processing the operation.
|
|
23
|
-
this.checkKeyUsages({ keyUsages, allowedKeyUsages: this.keyUsages });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public override async decrypt(): Promise<Uint8Array> {
|
|
27
|
-
throw new InvalidAccessError(`Requested operation 'decrypt' is not valid for ${this.name} keys.`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public override async encrypt(): Promise<Uint8Array> {
|
|
31
|
-
throw new InvalidAccessError(`Requested operation 'encrypt' is not valid for ${this.name} keys.`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public abstract generateKey(options: {
|
|
35
|
-
algorithm: IDCrypto.EcGenerateKeyOptions,
|
|
36
|
-
extractable: boolean,
|
|
37
|
-
keyUsages: IDCrypto.KeyUsage[]
|
|
38
|
-
}): Promise<IDCrypto.CryptoKeyPair>;
|
|
39
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { IDCrypto } from '../../types/iddwn-crypto.js';
|
|
2
|
-
|
|
3
|
-
import { InvalidAccessError } from '../errors.js';
|
|
4
|
-
import { BaseEllipticCurveAlgorithm } from './base.js';
|
|
5
|
-
import { checkRequiredProperty } from '../../utils.js';
|
|
6
|
-
|
|
7
|
-
export abstract class BaseEcdhAlgorithm extends BaseEllipticCurveAlgorithm {
|
|
8
|
-
|
|
9
|
-
public readonly name: string = 'ECDH';
|
|
10
|
-
|
|
11
|
-
public keyUsages: IDCrypto.KeyPairUsage = {
|
|
12
|
-
privateKey : ['deriveBits', 'deriveKey'],
|
|
13
|
-
publicKey : ['deriveBits', 'deriveKey'],
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
public checkAlgorithmOptions(options: {
|
|
17
|
-
algorithm: IDCrypto.EcdhDeriveKeyOptions,
|
|
18
|
-
baseKey: IDCrypto.CryptoKey
|
|
19
|
-
}): void {
|
|
20
|
-
const { algorithm, baseKey } = options;
|
|
21
|
-
// Algorithm specified in the operation must match the algorithm implementation processing the operation.
|
|
22
|
-
this.checkAlgorithmName({ algorithmName: algorithm.name });
|
|
23
|
-
// The algorithm object must contain a publicKey property.
|
|
24
|
-
checkRequiredProperty({ property: 'publicKey', inObject: algorithm });
|
|
25
|
-
// The publicKey object must be a CryptoKey.
|
|
26
|
-
this.checkCryptoKey({ key: algorithm.publicKey });
|
|
27
|
-
// The CryptoKey object must be a public key.
|
|
28
|
-
this.checkKeyType({ keyType: algorithm.publicKey.type, allowedKeyType: 'public' });
|
|
29
|
-
// The publicKey algorithm must match the algorithm implementation processing the operation.
|
|
30
|
-
this.checkKeyAlgorithm({ keyAlgorithmName: algorithm.publicKey.algorithm.name });
|
|
31
|
-
// The options object must contain a baseKey property.
|
|
32
|
-
checkRequiredProperty({ property: 'baseKey', inObject: options });
|
|
33
|
-
// The baseKey object must be a CryptoKey.
|
|
34
|
-
this.checkCryptoKey({ key: baseKey });
|
|
35
|
-
// The baseKey algorithm must match the algorithm implementation processing the operation.
|
|
36
|
-
this.checkKeyAlgorithm({ keyAlgorithmName: baseKey.algorithm.name });
|
|
37
|
-
// The CryptoKey object must be a private key.
|
|
38
|
-
this.checkKeyType({ keyType: baseKey.type, allowedKeyType: 'private' });
|
|
39
|
-
// The public and base key named curves must match.
|
|
40
|
-
if (('namedCurve' in algorithm.publicKey.algorithm) && ('namedCurve' in baseKey.algorithm)
|
|
41
|
-
&& (algorithm.publicKey.algorithm.namedCurve !== baseKey.algorithm.namedCurve)) {
|
|
42
|
-
throw new InvalidAccessError('The named curve of the publicKey and baseKey must match.');
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public override async sign(): Promise<Uint8Array> {
|
|
47
|
-
throw new InvalidAccessError(`Requested operation 'sign' is not valid for ${this.name} keys.`);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public override async verify(): Promise<boolean> {
|
|
51
|
-
throw new InvalidAccessError(`Requested operation 'verify' is not valid for ${this.name} keys.`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { IDCrypto } from '../../types/iddwn-crypto.js';
|
|
2
|
-
|
|
3
|
-
import { InvalidAccessError } from '../errors.js';
|
|
4
|
-
import { BaseEllipticCurveAlgorithm } from './base.js';
|
|
5
|
-
import { checkValidProperty, checkRequiredProperty } from '../../utils.js';
|
|
6
|
-
|
|
7
|
-
export abstract class BaseEcdsaAlgorithm extends BaseEllipticCurveAlgorithm {
|
|
8
|
-
|
|
9
|
-
public readonly name: string = 'ECDSA';
|
|
10
|
-
|
|
11
|
-
public readonly abstract hashAlgorithms: string[];
|
|
12
|
-
|
|
13
|
-
public readonly keyUsages: IDCrypto.KeyPairUsage = {
|
|
14
|
-
privateKey : ['sign'],
|
|
15
|
-
publicKey : ['verify'],
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
public checkAlgorithmOptions(options: {
|
|
19
|
-
algorithm: IDCrypto.EcdsaOptions
|
|
20
|
-
}): void {
|
|
21
|
-
const { algorithm } = options;
|
|
22
|
-
// Algorithm specified in the operation must match the algorithm implementation processing the operation.
|
|
23
|
-
this.checkAlgorithmName({ algorithmName: algorithm.name });
|
|
24
|
-
// The algorithm object must contain a hash property.
|
|
25
|
-
checkRequiredProperty({ property: 'hash', inObject: algorithm });
|
|
26
|
-
// The hash algorithm specified must be supported by the algorithm implementation processing the operation.
|
|
27
|
-
checkValidProperty({ property: algorithm.hash, allowedProperties: this.hashAlgorithms });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public override async deriveBits(): Promise<Uint8Array> {
|
|
31
|
-
throw new InvalidAccessError(`Requested operation 'deriveBits' is not valid for ${this.name} keys.`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public abstract sign(options: { algorithm: IDCrypto.EcdsaOptions; key: IDCrypto.CryptoKey; data: Uint8Array; }): Promise<Uint8Array>;
|
|
35
|
-
|
|
36
|
-
public abstract verify(options: { algorithm: IDCrypto.EcdsaOptions; key: IDCrypto.CryptoKey; signature: Uint8Array; data: Uint8Array; }): Promise<boolean>;
|
|
37
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { IDCrypto } from '../../types/iddwn-crypto.js';
|
|
2
|
-
|
|
3
|
-
import { InvalidAccessError } from '../errors.js';
|
|
4
|
-
import { BaseEllipticCurveAlgorithm } from './base.js';
|
|
5
|
-
|
|
6
|
-
export abstract class BaseEdDsaAlgorithm extends BaseEllipticCurveAlgorithm {
|
|
7
|
-
|
|
8
|
-
public readonly name: string = 'EdDSA';
|
|
9
|
-
|
|
10
|
-
public readonly keyUsages: IDCrypto.KeyPairUsage = {
|
|
11
|
-
privateKey : ['sign'],
|
|
12
|
-
publicKey : ['verify'],
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
public checkAlgorithmOptions(options: {
|
|
16
|
-
algorithm: IDCrypto.EdDsaOptions
|
|
17
|
-
}): void {
|
|
18
|
-
const { algorithm } = options;
|
|
19
|
-
// Algorithm specified in the operation must match the algorithm implementation processing the operation.
|
|
20
|
-
this.checkAlgorithmName({ algorithmName: algorithm.name });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public override async deriveBits(): Promise<Uint8Array> {
|
|
24
|
-
throw new InvalidAccessError(`Requested operation 'deriveBits' is not valid for ${this.name} keys.`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public abstract sign(options: { algorithm: IDCrypto.EdDsaOptions; key: IDCrypto.CryptoKey; data: Uint8Array; }): Promise<Uint8Array>;
|
|
28
|
-
|
|
29
|
-
public abstract verify(options: { algorithm: IDCrypto.EdDsaOptions; key: IDCrypto.CryptoKey; signature: Uint8Array; data: Uint8Array; }): Promise<boolean>;
|
|
30
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The methods of KeyManager and KeyManagementSystem interfaces return
|
|
3
|
-
* errors by rejecting the returned promise with a predefined exception
|
|
4
|
-
* defined in ECMAScript [ECMA-262] or DOMException.
|
|
5
|
-
*
|
|
6
|
-
* The following predefined exceptions are used: TypeError.
|
|
7
|
-
*
|
|
8
|
-
* The following DOMException types from [DOM4] are used:
|
|
9
|
-
* DataError: Data provided to an operation does not meet requirements
|
|
10
|
-
* InvalidAccessError: The requested operation is not valid for the provided key
|
|
11
|
-
* NotSupportedError: The algorithm is not supported
|
|
12
|
-
* OperationError: The operation failed for an operation-specific reason
|
|
13
|
-
* SyntaxError: A required parameter was missing or out-of-range
|
|
14
|
-
*
|
|
15
|
-
* Reference: https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-Exceptions
|
|
16
|
-
* Section 14.4. Exceptions
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
export class CryptoError extends Error {}
|
|
20
|
-
|
|
21
|
-
export class DataError extends CryptoError {}
|
|
22
|
-
|
|
23
|
-
export class InvalidAccessError extends CryptoError {}
|
|
24
|
-
|
|
25
|
-
export class NotSupportedError extends CryptoError {}
|
|
26
|
-
|
|
27
|
-
export class OperationError extends CryptoError {}
|
|
28
|
-
|
|
29
|
-
export class SyntaxError extends CryptoError {}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './pbkdf2.js';
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { IDCrypto } from '../../types/iddwn-crypto.js';
|
|
2
|
-
|
|
3
|
-
import { InvalidAccessError, OperationError } from '../errors.js';
|
|
4
|
-
import { CryptoAlgorithm } from '../crypto-algorithm.js';
|
|
5
|
-
import { checkRequiredProperty, checkValidProperty } from '../../utils.js';
|
|
6
|
-
import { universalTypeOf } from '../../../common/index.js';
|
|
7
|
-
|
|
8
|
-
export abstract class BasePbkdf2Algorithm extends CryptoAlgorithm {
|
|
9
|
-
|
|
10
|
-
public readonly name: string = 'PBKDF2';
|
|
11
|
-
|
|
12
|
-
public readonly abstract hashAlgorithms: string[];
|
|
13
|
-
|
|
14
|
-
public readonly keyUsages: IDCrypto.KeyUsage[] = ['deriveBits', 'deriveKey'];
|
|
15
|
-
|
|
16
|
-
public checkAlgorithmOptions(options: {
|
|
17
|
-
algorithm: IDCrypto.Pbkdf2Options,
|
|
18
|
-
baseKey: IDCrypto.CryptoKey
|
|
19
|
-
}): void {
|
|
20
|
-
const { algorithm, baseKey } = options;
|
|
21
|
-
// Algorithm specified in the operation must match the algorithm implementation processing the operation.
|
|
22
|
-
this.checkAlgorithmName({ algorithmName: algorithm.name });
|
|
23
|
-
// The algorithm object must contain a hash property.
|
|
24
|
-
checkRequiredProperty({ property: 'hash', inObject: algorithm });
|
|
25
|
-
// The hash algorithm specified must be supported by the algorithm implementation processing the operation.
|
|
26
|
-
checkValidProperty({ property: algorithm.hash, allowedProperties: this.hashAlgorithms });
|
|
27
|
-
// The algorithm object must contain a iterations property.
|
|
28
|
-
checkRequiredProperty({ property: 'iterations', inObject: algorithm });
|
|
29
|
-
// The iterations value must a number.
|
|
30
|
-
if (!(universalTypeOf(algorithm.iterations) === 'Number')) {
|
|
31
|
-
throw new TypeError(`Algorithm 'iterations' is not of type: Number.`);
|
|
32
|
-
}
|
|
33
|
-
// The iterations value must be greater than 0.
|
|
34
|
-
if (algorithm.iterations < 1) {
|
|
35
|
-
throw new OperationError(`Algorithm 'iterations' must be > 0.`);
|
|
36
|
-
}
|
|
37
|
-
// The algorithm object must contain a salt property.
|
|
38
|
-
checkRequiredProperty({ property: 'salt', inObject: algorithm });
|
|
39
|
-
// The salt must a Uint8Array.
|
|
40
|
-
if (!(universalTypeOf(algorithm.salt) === 'Uint8Array')) {
|
|
41
|
-
throw new TypeError(`Algorithm 'salt' is not of type: Uint8Array.`);
|
|
42
|
-
}
|
|
43
|
-
// The options object must contain a baseKey property.
|
|
44
|
-
checkRequiredProperty({ property: 'baseKey', inObject: options });
|
|
45
|
-
// The baseKey object must be a CryptoKey.
|
|
46
|
-
this.checkCryptoKey({ key: baseKey });
|
|
47
|
-
// The baseKey algorithm must match the algorithm implementation processing the operation.
|
|
48
|
-
this.checkKeyAlgorithm({ keyAlgorithmName: baseKey.algorithm.name });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public checkImportKey(options: {
|
|
52
|
-
algorithm: IDCrypto.Algorithm,
|
|
53
|
-
format: IDCrypto.KeyFormat,
|
|
54
|
-
extractable: boolean,
|
|
55
|
-
keyUsages: IDCrypto.KeyUsage[]
|
|
56
|
-
}): void {
|
|
57
|
-
const { algorithm, format, extractable, keyUsages } = options;
|
|
58
|
-
// Algorithm specified in the operation must match the algorithm implementation processing the operation.
|
|
59
|
-
this.checkAlgorithmName({ algorithmName: algorithm.name });
|
|
60
|
-
// The format specified must be 'raw'.
|
|
61
|
-
if (format !== 'raw') {
|
|
62
|
-
throw new SyntaxError(`Format '${format}' not supported. Only 'raw' is supported.`);
|
|
63
|
-
}
|
|
64
|
-
// The extractable value specified must be false.
|
|
65
|
-
if (extractable !== false) {
|
|
66
|
-
throw new SyntaxError(`Extractable '${extractable}' not supported. Only 'false' is supported.`);
|
|
67
|
-
}
|
|
68
|
-
// The key usages specified must be permitted by the algorithm implementation processing the operation.
|
|
69
|
-
this.checkKeyUsages({ keyUsages, allowedKeyUsages: this.keyUsages });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public override async decrypt(): Promise<Uint8Array> {
|
|
73
|
-
throw new InvalidAccessError(`Requested operation 'decrypt' is not valid for ${this.name} keys.`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public override async encrypt(): Promise<Uint8Array> {
|
|
77
|
-
throw new InvalidAccessError(`Requested operation 'encrypt' is not valid for ${this.name} keys.`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public override async generateKey(): Promise<IDCrypto.CryptoKey> {
|
|
81
|
-
throw new InvalidAccessError(`Requested operation 'generateKey' is not valid for ${this.name} keys.`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public override async sign(): Promise<Uint8Array> {
|
|
85
|
-
throw new InvalidAccessError(`Requested operation 'sign' is not valid for ${this.name} keys.`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public override async verify(): Promise<boolean> {
|
|
89
|
-
throw new InvalidAccessError(`Requested operation 'verify' is not valid for ${this.name} keys.`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { universalTypeOf } from '../../common/index.js';
|
|
2
|
-
|
|
3
|
-
import type { IDCrypto } from '../types/iddwn-crypto.js';
|
|
4
|
-
|
|
5
|
-
import { AesCtr } from '../crypto-primitives/index.js';
|
|
6
|
-
import { BaseAesCtrAlgorithm, CryptoKey } from '../algorithms-api/index.js';
|
|
7
|
-
|
|
8
|
-
export class AesCtrAlgorithm extends BaseAesCtrAlgorithm {
|
|
9
|
-
public async decrypt(options: {
|
|
10
|
-
algorithm: IDCrypto.AesCtrOptions,
|
|
11
|
-
key: IDCrypto.CryptoKey,
|
|
12
|
-
data: Uint8Array
|
|
13
|
-
}): Promise<Uint8Array> {
|
|
14
|
-
const { algorithm, key, data } = options;
|
|
15
|
-
|
|
16
|
-
this.checkAlgorithmOptions({ algorithm, key });
|
|
17
|
-
// The secret key must be allowed to be used for 'decrypt' operations.
|
|
18
|
-
this.checkKeyUsages({ keyUsages: ['decrypt'], allowedKeyUsages: key.usages });
|
|
19
|
-
|
|
20
|
-
const plaintext = AesCtr.decrypt({
|
|
21
|
-
counter : algorithm.counter,
|
|
22
|
-
data : data,
|
|
23
|
-
key : key.material,
|
|
24
|
-
length : algorithm.length
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return plaintext;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public async encrypt(options: {
|
|
31
|
-
algorithm: IDCrypto.AesCtrOptions,
|
|
32
|
-
key: IDCrypto.CryptoKey,
|
|
33
|
-
data: Uint8Array
|
|
34
|
-
}): Promise<Uint8Array> {
|
|
35
|
-
const { algorithm, key, data } = options;
|
|
36
|
-
|
|
37
|
-
this.checkAlgorithmOptions({ algorithm, key });
|
|
38
|
-
// The secret key must be allowed to be used for 'encrypt' operations.
|
|
39
|
-
this.checkKeyUsages({ keyUsages: ['encrypt'], allowedKeyUsages: key.usages });
|
|
40
|
-
|
|
41
|
-
const ciphertext = AesCtr.encrypt({
|
|
42
|
-
counter : algorithm.counter,
|
|
43
|
-
data : data,
|
|
44
|
-
key : key.material,
|
|
45
|
-
length : algorithm.length
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return ciphertext;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public async generateKey(options: {
|
|
52
|
-
algorithm: IDCrypto.AesGenerateKeyOptions,
|
|
53
|
-
extractable: boolean,
|
|
54
|
-
keyUsages: IDCrypto.KeyUsage[]
|
|
55
|
-
}): Promise<IDCrypto.CryptoKey> {
|
|
56
|
-
const { algorithm, extractable, keyUsages } = options;
|
|
57
|
-
|
|
58
|
-
this.checkGenerateKey({ algorithm, keyUsages });
|
|
59
|
-
|
|
60
|
-
const secretKey = await AesCtr.generateKey({ length: algorithm.length });
|
|
61
|
-
|
|
62
|
-
if (universalTypeOf(secretKey) !== 'Uint8Array') {
|
|
63
|
-
throw new Error('Operation failed to generate key.');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const secretCryptoKey = new CryptoKey(algorithm, extractable, secretKey, 'secret', this.keyUsages);
|
|
67
|
-
|
|
68
|
-
return secretCryptoKey;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type { IDCrypto } from '../types/iddwn-crypto.js';
|
|
2
|
-
import type { BbsKeyPair } from '../crypto-primitives/bbs.js';
|
|
3
|
-
|
|
4
|
-
import { Bbs } from '../crypto-primitives/bbs.js';
|
|
5
|
-
import { CryptoKey } from '../algorithms-api/index.js';
|
|
6
|
-
|
|
7
|
-
export interface BbsGenerateKeyOptions extends IDCrypto.Algorithm {
|
|
8
|
-
name: 'BBS';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface BbsSignOptions extends IDCrypto.Algorithm {
|
|
12
|
-
name: 'BBS';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* High-level BBS+ signature algorithm implementing multi-message signing,
|
|
17
|
-
* verification, and zero-knowledge selective disclosure proof operations.
|
|
18
|
-
*
|
|
19
|
-
* Unlike EdDSA/ECDSA which sign a single data buffer, BBS+ signs an array
|
|
20
|
-
* of messages and supports deriving proofs that reveal only a subset.
|
|
21
|
-
*/
|
|
22
|
-
export class BbsAlgorithm {
|
|
23
|
-
public readonly name = 'BBS';
|
|
24
|
-
|
|
25
|
-
public readonly keyUsages: IDCrypto.KeyPairUsage = {
|
|
26
|
-
privateKey: ['sign'],
|
|
27
|
-
publicKey: ['verify'],
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Generates a BLS12-381 G2 key pair for BBS+ operations.
|
|
32
|
-
*/
|
|
33
|
-
public async generateKey(): Promise<IDCrypto.CryptoKeyPair> {
|
|
34
|
-
const keyPair = await Bbs.generateKeyPair();
|
|
35
|
-
|
|
36
|
-
const algorithm: BbsGenerateKeyOptions = { name: 'BBS' };
|
|
37
|
-
|
|
38
|
-
const cryptoKeyPair: IDCrypto.CryptoKeyPair = {
|
|
39
|
-
privateKey: new CryptoKey(algorithm, true, keyPair.secretKey, 'private', ['sign']),
|
|
40
|
-
publicKey: new CryptoKey(algorithm, true, keyPair.publicKey, 'public', ['verify']),
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return cryptoKeyPair;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Signs multiple messages with BBS+ producing a single signature.
|
|
48
|
-
*
|
|
49
|
-
* @param options.keyPair - Raw BBS key pair (publicKey + secretKey as Uint8Array).
|
|
50
|
-
* @param options.messages - Array of messages to sign.
|
|
51
|
-
* @returns The BBS+ signature.
|
|
52
|
-
*/
|
|
53
|
-
public async sign(options: {
|
|
54
|
-
keyPair: BbsKeyPair;
|
|
55
|
-
messages: Uint8Array[];
|
|
56
|
-
}): Promise<Uint8Array> {
|
|
57
|
-
return Bbs.sign(options);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Verifies a BBS+ signature against the full message set.
|
|
62
|
-
*
|
|
63
|
-
* @param options.publicKey - The issuer's BLS12-381 G2 public key.
|
|
64
|
-
* @param options.signature - The BBS+ signature to verify.
|
|
65
|
-
* @param options.messages - The complete set of signed messages.
|
|
66
|
-
*/
|
|
67
|
-
public async verify(options: {
|
|
68
|
-
publicKey: Uint8Array;
|
|
69
|
-
signature: Uint8Array;
|
|
70
|
-
messages: Uint8Array[];
|
|
71
|
-
}): Promise<boolean> {
|
|
72
|
-
return Bbs.verify(options);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Derives a zero-knowledge proof revealing only selected messages.
|
|
77
|
-
*
|
|
78
|
-
* @param options.publicKey - Issuer's public key.
|
|
79
|
-
* @param options.signature - Original BBS+ signature.
|
|
80
|
-
* @param options.messages - Complete message set.
|
|
81
|
-
* @param options.revealed - Indices of messages to disclose.
|
|
82
|
-
* @param options.nonce - Session-binding nonce.
|
|
83
|
-
*/
|
|
84
|
-
public async createProof(options: {
|
|
85
|
-
publicKey: Uint8Array;
|
|
86
|
-
signature: Uint8Array;
|
|
87
|
-
messages: Uint8Array[];
|
|
88
|
-
revealed: number[];
|
|
89
|
-
nonce: Uint8Array;
|
|
90
|
-
}): Promise<Uint8Array> {
|
|
91
|
-
return Bbs.createProof(options);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Verifies a BBS+ selective disclosure proof.
|
|
96
|
-
*
|
|
97
|
-
* @param options.publicKey - Issuer's public key.
|
|
98
|
-
* @param options.proof - The derived proof.
|
|
99
|
-
* @param options.messages - Only the disclosed messages.
|
|
100
|
-
* @param options.nonce - The nonce used during proof creation.
|
|
101
|
-
*/
|
|
102
|
-
public async verifyProof(options: {
|
|
103
|
-
publicKey: Uint8Array;
|
|
104
|
-
proof: Uint8Array;
|
|
105
|
-
messages: Uint8Array[];
|
|
106
|
-
nonce: Uint8Array;
|
|
107
|
-
}): Promise<boolean> {
|
|
108
|
-
return Bbs.verifyProof(options);
|
|
109
|
-
}
|
|
110
|
-
}
|