@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,119 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
-
export namespace IDCrypto {
|
|
3
|
-
export interface AesCtrOptions extends Algorithm {
|
|
4
|
-
counter: Uint8Array;
|
|
5
|
-
length: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface AesGenerateKeyOptions extends Algorithm {
|
|
9
|
-
length: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface AesGcmOptions extends Algorithm {
|
|
13
|
-
additionalData?: Uint8Array;
|
|
14
|
-
iv: Uint8Array;
|
|
15
|
-
tagLength?: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface Algorithm {
|
|
19
|
-
name: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type AlgorithmIdentifier = Algorithm;
|
|
23
|
-
|
|
24
|
-
export interface CryptoKey {
|
|
25
|
-
algorithm: IDCrypto.Algorithm;
|
|
26
|
-
extractable: boolean;
|
|
27
|
-
material: Uint8Array;
|
|
28
|
-
type: KeyType;
|
|
29
|
-
usages: KeyUsage[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface CryptoKeyPair {
|
|
33
|
-
privateKey: CryptoKey;
|
|
34
|
-
publicKey: CryptoKey;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface EcdsaOptions extends Algorithm {
|
|
38
|
-
hash: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface EcGenerateKeyOptions extends Algorithm {
|
|
42
|
-
namedCurve: NamedCurve;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface EcdhDeriveKeyOptions extends Algorithm {
|
|
46
|
-
publicKey: CryptoKey;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface EcdsaGenerateKeyOptions extends EcGenerateKeyOptions {
|
|
50
|
-
compressedPublicKey?: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export type EdDsaGenerateKeyOptions = EcGenerateKeyOptions
|
|
54
|
-
|
|
55
|
-
export type EdDsaOptions = Algorithm
|
|
56
|
-
|
|
57
|
-
export type GenerateKeyOptions = AesGenerateKeyOptions | EcGenerateKeyOptions | HmacGenerateKeyOptions;
|
|
58
|
-
|
|
59
|
-
export interface HmacGenerateKeyOptions extends Algorithm {
|
|
60
|
-
hash: AlgorithmIdentifier;
|
|
61
|
-
length?: number;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface KeyAlgorithm {
|
|
65
|
-
name: string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export type KeyFormat = 'jwk' | 'pkcs8' | 'raw' | 'spki';
|
|
69
|
-
|
|
70
|
-
export interface KeyPairUsage {
|
|
71
|
-
privateKey: KeyUsage[];
|
|
72
|
-
publicKey: KeyUsage[];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* KeyType
|
|
77
|
-
*
|
|
78
|
-
* The read-only `type` property indicates which kind of key
|
|
79
|
-
* is represented by the object.
|
|
80
|
-
*
|
|
81
|
-
* It can have the following string values:
|
|
82
|
-
*
|
|
83
|
-
* "secret": This key is a secret key for use with a symmetric algorithm.
|
|
84
|
-
* "private": This key is the private half of an asymmetric algorithm's `ManagedKeyPair`.
|
|
85
|
-
* "public": This key is the public half of an asymmetric algorithm's `ManagedKeyPair`.
|
|
86
|
-
*/
|
|
87
|
-
export type KeyType = 'private' | 'public' | 'secret';
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* KeyUsage
|
|
91
|
-
*
|
|
92
|
-
* The read-only usage property indicates what can be done with the key.
|
|
93
|
-
*
|
|
94
|
-
* An Array of strings from the following list:
|
|
95
|
-
*
|
|
96
|
-
* "encrypt": The key may be used to encrypt messages.
|
|
97
|
-
* "decrypt": The key may be used to decrypt messages.
|
|
98
|
-
* "sign": The key may be used to sign messages.
|
|
99
|
-
* "verify": The key may be used to verify signatures.
|
|
100
|
-
* "deriveKey": The key may be used in deriving a new key.
|
|
101
|
-
* "deriveBits": The key may be used in deriving bits.
|
|
102
|
-
* "wrapKey": The key may be used to wrap a key.
|
|
103
|
-
* "unwrapKey": The key may be used to unwrap a key.
|
|
104
|
-
*
|
|
105
|
-
* Reference: IANA "JSON Web Key Operations" registry
|
|
106
|
-
* https://www.iana.org/assignments/jose/jose.xhtml#web-key-operations
|
|
107
|
-
*/
|
|
108
|
-
export type KeyUsage = 'encrypt' | 'decrypt' | 'sign' | 'verify' | 'deriveKey' | 'deriveBits' | 'wrapKey' | 'unwrapKey';
|
|
109
|
-
|
|
110
|
-
export type NamedCurve = string;
|
|
111
|
-
|
|
112
|
-
export interface Pbkdf2Options extends Algorithm {
|
|
113
|
-
hash: string;
|
|
114
|
-
iterations: number;
|
|
115
|
-
salt: Uint8Array;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export type PrivateKeyType = 'private' | 'secret';
|
|
119
|
-
}
|
package/src/crypto/utils.ts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
// import type { BytesKeyPair, IDCrypto } from './types/index.js';
|
|
2
|
-
import type { IDCrypto } from './types/iddwn-crypto.js';
|
|
3
|
-
import type { BytesKeyPair } from './types/crypto-key.js';
|
|
4
|
-
|
|
5
|
-
import { Convert, Multicodec, universalTypeOf } from '../common/index.js';
|
|
6
|
-
import { bytesToHex, randomBytes as nobleRandomBytes } from '@noble/hashes/utils';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Checks whether the properties object provided contains the specified property.
|
|
10
|
-
*
|
|
11
|
-
* @param property Property key to check for.
|
|
12
|
-
* @param properties Properties object to check within.
|
|
13
|
-
* @returns void
|
|
14
|
-
* @throws {SyntaxError} If the property is not a key in the properties object.
|
|
15
|
-
*/
|
|
16
|
-
export function checkRequiredProperty(options: {
|
|
17
|
-
property: string,
|
|
18
|
-
inObject: object
|
|
19
|
-
}): void {
|
|
20
|
-
if (!options || options.property === undefined || options.inObject === undefined) {
|
|
21
|
-
throw new TypeError(`One or more required parameters missing: 'property, properties'`);
|
|
22
|
-
}
|
|
23
|
-
const { property, inObject } = options;
|
|
24
|
-
if (!(property in inObject)) {
|
|
25
|
-
throw new TypeError(`Required parameter missing: '${property}'`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Checks whether the property specified is a member of the list of valid properties.
|
|
31
|
-
*
|
|
32
|
-
* @param property Property key to check for.
|
|
33
|
-
* @param allowedProperties Properties Array, Map, or Set to check within.
|
|
34
|
-
* @returns void
|
|
35
|
-
* @throws {SyntaxError} If the property is not a member of the allowedProperties Array, Map, or Set.
|
|
36
|
-
*/
|
|
37
|
-
export function checkValidProperty(options: {
|
|
38
|
-
property: string, allowedProperties: Array<string> | Map<string, unknown> | Set<string>
|
|
39
|
-
}): void {
|
|
40
|
-
if (!options || options.property === undefined || options.allowedProperties === undefined) {
|
|
41
|
-
throw new TypeError(`One or more required parameters missing: 'property, allowedProperties'`);
|
|
42
|
-
}
|
|
43
|
-
const { property, allowedProperties } = options;
|
|
44
|
-
if (
|
|
45
|
-
(Array.isArray(allowedProperties) && !allowedProperties.includes(property)) ||
|
|
46
|
-
(allowedProperties instanceof Set && !allowedProperties.has(property)) ||
|
|
47
|
-
(allowedProperties instanceof Map && !allowedProperties.has(property))
|
|
48
|
-
) {
|
|
49
|
-
const validProperties = Array.from((allowedProperties instanceof Map) ? allowedProperties.keys() : allowedProperties).join(', ');
|
|
50
|
-
throw new TypeError(`Out of range: '${property}'. Must be one of '${validProperties}'`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Type guard function to check if the given key is a raw key pair
|
|
56
|
-
* of Uint8Array typed arrays.
|
|
57
|
-
*
|
|
58
|
-
* @param key The key to check.
|
|
59
|
-
* @returns True if the key is a pair of Uint8Array typed arrays, false otherwise.
|
|
60
|
-
*/
|
|
61
|
-
export function isBytesKeyPair(key: BytesKeyPair | undefined): key is BytesKeyPair {
|
|
62
|
-
return (key && 'privateKey' in key && 'publicKey' in key &&
|
|
63
|
-
universalTypeOf(key.privateKey) === 'Uint8Array' &&
|
|
64
|
-
universalTypeOf(key.publicKey) === 'Uint8Array') ? true : false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Type guard function to check if the given key is a
|
|
69
|
-
* IDCrypto.CryptoKeyPair.
|
|
70
|
-
*
|
|
71
|
-
* @param key The key to check.
|
|
72
|
-
* @returns True if the key is a CryptoKeyPair, false otherwise.
|
|
73
|
-
*/
|
|
74
|
-
export function isCryptoKeyPair(key: IDCrypto.CryptoKey | IDCrypto.CryptoKeyPair): key is IDCrypto.CryptoKeyPair {
|
|
75
|
-
return key && 'privateKey' in key && 'publicKey' in key;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function keyToMultibaseId(options: {
|
|
79
|
-
key: Uint8Array,
|
|
80
|
-
multicodecCode?: number,
|
|
81
|
-
multicodecName?: string
|
|
82
|
-
}): string {
|
|
83
|
-
const { key, multicodecCode, multicodecName } = options;
|
|
84
|
-
const prefixedKey = Multicodec.addPrefix({ code: multicodecCode, data: key, name: multicodecName });
|
|
85
|
-
const prefixedKeyB58 = Convert.uint8Array(prefixedKey).toBase58Btc();
|
|
86
|
-
const multibaseKeyId = Convert.base58Btc(prefixedKeyB58).toMultibase();
|
|
87
|
-
|
|
88
|
-
return multibaseKeyId;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Checks if the Web Crypto API is supported in the current runtime environment.
|
|
94
|
-
*
|
|
95
|
-
* The function uses `globalThis` to provide a universal reference to the global
|
|
96
|
-
* scope, regardless of the environment. `globalThis` is a standard feature introduced
|
|
97
|
-
* in ECMAScript 2020 that is agnostic to the underlying JavaScript environment, making
|
|
98
|
-
* the code portable across browser, Node.js, and Web Workers environments.
|
|
99
|
-
*
|
|
100
|
-
* In a web browser, `globalThis` is equivalent to the `window` object. In Node.js, it
|
|
101
|
-
* is equivalent to the `global` object, and in Web Workers, it corresponds to `self`.
|
|
102
|
-
*
|
|
103
|
-
* This method checks for the `crypto` object and its `subtle` property on the global scope
|
|
104
|
-
* to determine the availability of the Web Crypto API. If both are present, the API is
|
|
105
|
-
* supported; otherwise, it is not.
|
|
106
|
-
*
|
|
107
|
-
* @returns A boolean indicating whether the Web Crypto API is supported in the current environment.
|
|
108
|
-
*
|
|
109
|
-
* Example usage:
|
|
110
|
-
*
|
|
111
|
-
* ```ts
|
|
112
|
-
* if (isWebCryptoSupported()) {
|
|
113
|
-
* console.log('Crypto operations can be performed');
|
|
114
|
-
* } else {
|
|
115
|
-
* console.log('Crypto operations are not supported in this environment');
|
|
116
|
-
* }
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
export function isWebCryptoSupported(): boolean {
|
|
120
|
-
if (globalThis.crypto && globalThis.crypto.subtle) {
|
|
121
|
-
return true;
|
|
122
|
-
} else {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function multibaseIdToKey(options: {
|
|
128
|
-
multibaseKeyId: string
|
|
129
|
-
}): { key: Uint8Array, multicodecCode: number, multicodecName: string } {
|
|
130
|
-
const { multibaseKeyId } = options;
|
|
131
|
-
|
|
132
|
-
const prefixedKeyB58 = Convert.multibase(multibaseKeyId).toBase58Btc();
|
|
133
|
-
const prefixedKey = Convert.base58Btc(prefixedKeyB58).toUint8Array();
|
|
134
|
-
const { code, data, name } = Multicodec.removePrefix({ prefixedData: prefixedKey });
|
|
135
|
-
|
|
136
|
-
return { key: data, multicodecCode: code, multicodecName: name };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Generates secure pseudorandom values of the specified length using
|
|
141
|
-
* `crypto.getRandomValues`, which defers to the operating system.
|
|
142
|
-
*
|
|
143
|
-
* This function is a wrapper around `randomBytes` from the '@noble/hashes'
|
|
144
|
-
* package. It's designed to be cryptographically strong, suitable for
|
|
145
|
-
* generating keys, initialization vectors, and other random values.
|
|
146
|
-
*
|
|
147
|
-
* @param bytesLength - The number of bytes to generate.
|
|
148
|
-
* @returns A Uint8Array containing the generated random bytes.
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* const bytes = randomBytes(32); // Generates 32 random bytes
|
|
152
|
-
*
|
|
153
|
-
* @see {@link https://www.npmjs.com/package/@noble/hashes | @noble/hashes on NPM}
|
|
154
|
-
* for more information about the underlying implementation.
|
|
155
|
-
*/
|
|
156
|
-
export function randomBytes(bytesLength: number): Uint8Array {
|
|
157
|
-
return nobleRandomBytes(bytesLength);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Generates a UUID (Universally Unique Identifier) using a
|
|
162
|
-
* cryptographically strong random number generator following
|
|
163
|
-
* the version 4 format, as specified in RFC 4122.
|
|
164
|
-
*
|
|
165
|
-
* A version 4 UUID is a randomly generated UUID. The 13th character
|
|
166
|
-
* is set to '4' to denote version 4, and the 17th character is one
|
|
167
|
-
* of '8', '9', 'A', or 'B' to comply with the variant 1 format of
|
|
168
|
-
* UUIDs (the high bits are set to '10').
|
|
169
|
-
*
|
|
170
|
-
* The UUID is a 36 character string, including hyphens, and looks like this:
|
|
171
|
-
* xxxxxxxx-xxxx-4xxx-axxx-xxxxxxxxxxxx
|
|
172
|
-
*
|
|
173
|
-
* Note that while UUIDs are not guaranteed to be unique, they are
|
|
174
|
-
* practically unique" given the large number of possible UUIDs and
|
|
175
|
-
* the randomness of generation.
|
|
176
|
-
*
|
|
177
|
-
* After generating the UUID, the function securely wipes the memory
|
|
178
|
-
* areas used to hold temporary values to prevent any possibility of
|
|
179
|
-
* the random values being unintentionally leaked or retained in memory.
|
|
180
|
-
*
|
|
181
|
-
* @returns A UUID string in version 4 format.
|
|
182
|
-
*/
|
|
183
|
-
export function randomUuid(): string {
|
|
184
|
-
const bytes = randomBytes(16);
|
|
185
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40; // set version 4
|
|
186
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80; // set variant 1
|
|
187
|
-
const hex = bytesToHex(bytes);
|
|
188
|
-
bytes.fill(0); // wipe the random values array
|
|
189
|
-
const segments = [
|
|
190
|
-
hex.slice(0, 8),
|
|
191
|
-
hex.slice(8, 12),
|
|
192
|
-
hex.slice(12, 16),
|
|
193
|
-
hex.slice(16, 20),
|
|
194
|
-
hex.slice(20, 32)
|
|
195
|
-
];
|
|
196
|
-
const uuid = segments.join('-');
|
|
197
|
-
segments.fill('0'); // wipe the segments array
|
|
198
|
-
|
|
199
|
-
return uuid;
|
|
200
|
-
}
|
package/src/did-api.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { IDAgent } from './agent/index.js';
|
|
2
|
-
import type { DidResolutionOptions, DidResolutionResult } from './dids/index.js';
|
|
3
|
-
|
|
4
|
-
import { DidMessage } from './agent/did-manager.js';
|
|
5
|
-
|
|
6
|
-
import type { DidService } from './dids/types.js';
|
|
7
|
-
|
|
8
|
-
import { DidIonMethod } from './dids/index.js';
|
|
9
|
-
import { getServiceDwnEndpoints } from './service-options.js';
|
|
10
|
-
|
|
11
|
-
import { getServices, isDwnServiceEndpoint } from './dids/utils.js';
|
|
12
|
-
|
|
13
|
-
export type CustomServiceOptions = {
|
|
14
|
-
serviceOptions?: {
|
|
15
|
-
dwnEndpoints?: string[]
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The DID API is used to create and resolve DIDs.
|
|
21
|
-
*
|
|
22
|
-
* @beta
|
|
23
|
-
*/
|
|
24
|
-
export class DidApi {
|
|
25
|
-
private agent: IDAgent;
|
|
26
|
-
private connectedDid: string;
|
|
27
|
-
didUtils: any;
|
|
28
|
-
|
|
29
|
-
constructor(options: { agent: IDAgent, connectedDid: string }) {
|
|
30
|
-
this.agent = options.agent;
|
|
31
|
-
this.connectedDid = options.connectedDid;
|
|
32
|
-
this.didUtils = { getServices, isDwnServiceEndpoint };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Resolves a DID to a DID Resolution Result.
|
|
37
|
-
*
|
|
38
|
-
* @param didUrl - The DID or DID URL to resolve.
|
|
39
|
-
* @returns A promise that resolves to the DID Resolution Result.
|
|
40
|
-
*/
|
|
41
|
-
async resolve(didUrl: string, resolutionOptions?: DidResolutionOptions): Promise<DidResolutionResult> {
|
|
42
|
-
const agentResponse = await this.agent.processDidRequest({
|
|
43
|
-
messageOptions : { didUrl, resolutionOptions },
|
|
44
|
-
messageType : DidMessage.Resolve
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const { result } = agentResponse;
|
|
48
|
-
|
|
49
|
-
return result as DidResolutionResult;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Resolves a DID to a DID Resolution Result.
|
|
54
|
-
*
|
|
55
|
-
* @param options - custom service options
|
|
56
|
-
* @returns A promise that resolves to the DID Resolution Result.
|
|
57
|
-
*/
|
|
58
|
-
async create(options: CustomServiceOptions = {}): Promise<any> {
|
|
59
|
-
const services: DidService[] = [{
|
|
60
|
-
id : '#dwn',
|
|
61
|
-
type : 'DecentralizedWebNode',
|
|
62
|
-
serviceEndpoint : {
|
|
63
|
-
nodes: options?.serviceOptions?.dwnEndpoints ? options?.serviceOptions?.dwnEndpoints : await getServiceDwnEndpoints()
|
|
64
|
-
}
|
|
65
|
-
}];
|
|
66
|
-
|
|
67
|
-
return await DidIonMethod.create({
|
|
68
|
-
services,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}
|