@did-btcr2/common 5.0.0 → 8.0.0
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/canonicalization.js +95 -230
- package/dist/cjs/canonicalization.js.map +1 -1
- package/dist/cjs/errors.js +3 -8
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.js +0 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/json-patch.js +1 -1
- package/dist/cjs/json-patch.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/date.js +3 -4
- package/dist/cjs/utils/date.js.map +1 -1
- package/dist/cjs/utils/json.js +2 -9
- package/dist/cjs/utils/json.js.map +1 -1
- package/dist/esm/canonicalization.js +95 -230
- package/dist/esm/canonicalization.js.map +1 -1
- package/dist/esm/errors.js +3 -8
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/json-patch.js +1 -1
- package/dist/esm/json-patch.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/date.js +3 -4
- package/dist/esm/utils/date.js.map +1 -1
- package/dist/esm/utils/json.js +2 -9
- package/dist/esm/utils/json.js.map +1 -1
- package/dist/types/canonicalization.d.ts +46 -137
- package/dist/types/canonicalization.d.ts.map +1 -1
- package/dist/types/errors.d.ts +5 -6
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/json-patch.d.ts +2 -1
- package/dist/types/json-patch.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -28
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/date.d.ts +4 -4
- package/dist/types/utils/date.d.ts.map +1 -1
- package/dist/types/utils/json.d.ts +2 -16
- package/dist/types/utils/json.d.ts.map +1 -1
- package/dist/types/utils/string.d.ts +1 -0
- package/package.json +11 -5
- package/src/canonicalization.ts +100 -254
- package/src/errors.ts +3 -15
- package/src/index.ts +0 -3
- package/src/json-patch.ts +2 -2
- package/src/types.ts +7 -30
- package/src/utils/date.ts +3 -4
- package/src/utils/json.ts +3 -10
- package/dist/cjs/constants.js +0 -119
- package/dist/cjs/constants.js.map +0 -1
- package/dist/cjs/logger.js +0 -155
- package/dist/cjs/logger.js.map +0 -1
- package/dist/cjs/utils/set.js +0 -23
- package/dist/cjs/utils/set.js.map +0 -1
- package/dist/esm/constants.js +0 -119
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/logger.js +0 -155
- package/dist/esm/logger.js.map +0 -1
- package/dist/esm/utils/set.js +0 -23
- package/dist/esm/utils/set.js.map +0 -1
- package/dist/types/constants.d.ts +0 -97
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/logger.d.ts +0 -64
- package/dist/types/logger.d.ts.map +0 -1
- package/dist/types/utils/set.d.ts +0 -14
- package/dist/types/utils/set.d.ts.map +0 -1
- package/src/constants.ts +0 -127
- package/src/logger.ts +0 -173
- package/src/utils/set.ts +0 -23
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { Bytes, HashHex } from './types.js';
|
|
2
|
-
export declare const OP_RETURN = 106;
|
|
3
|
-
export declare const OP_PUSH32 = 32;
|
|
4
|
-
export declare const VALID_HRP: string[];
|
|
5
|
-
export declare const MULTIBASE_URI_PREFIX = "urn:mb:";
|
|
6
|
-
export declare const INITIAL_BLOCK_REWARD = 50;
|
|
7
|
-
export declare const HALVING_INTERVAL = 150;
|
|
8
|
-
export declare const COINBASE_MATURITY_DELAY = 100;
|
|
9
|
-
export declare const DEFAULT_POLAR_CONFIG: {
|
|
10
|
-
username: string;
|
|
11
|
-
password: string;
|
|
12
|
-
host: string;
|
|
13
|
-
allowDefaultWallet: boolean;
|
|
14
|
-
version: string;
|
|
15
|
-
};
|
|
16
|
-
export declare const DEFAULT_REST_CONFIG: {
|
|
17
|
-
host: string;
|
|
18
|
-
};
|
|
19
|
-
export declare const DEFAULT_RPC_CONFIG: {
|
|
20
|
-
username: string;
|
|
21
|
-
password: string;
|
|
22
|
-
host: string;
|
|
23
|
-
allowDefaultWallet: boolean;
|
|
24
|
-
version: string;
|
|
25
|
-
};
|
|
26
|
-
export declare const DEFAULT_BLOCK_CONFIRMATIONS = 7;
|
|
27
|
-
/**
|
|
28
|
-
* Load a default RPC config, allowing environment overrides to avoid hard-coding credentials/hosts in bundles.
|
|
29
|
-
* @returns {typeof DEFAULT_POLAR_CONFIG} The RPC config.
|
|
30
|
-
*/
|
|
31
|
-
export declare function getDefaultRpcConfig(): typeof DEFAULT_POLAR_CONFIG;
|
|
32
|
-
export declare const BIP340_PUBLIC_KEY_MULTIBASE_PREFIX: Bytes;
|
|
33
|
-
export declare const BIP340_PUBLIC_KEY_MULTIBASE_PREFIX_HASH: HashHex;
|
|
34
|
-
export declare const BIP340_SECRET_KEY_MULTIBASE_PREFIX: Bytes;
|
|
35
|
-
export declare const BIP340_SECRET_KEY_MULTIBASE_PREFIX_HASH: HashHex;
|
|
36
|
-
export declare const B256: bigint;
|
|
37
|
-
export declare const P: bigint;
|
|
38
|
-
export declare const N: bigint;
|
|
39
|
-
export declare const Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240n;
|
|
40
|
-
export declare const Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424n;
|
|
41
|
-
export declare const a = 0n;
|
|
42
|
-
export declare const b = 7n;
|
|
43
|
-
export declare const p: bigint;
|
|
44
|
-
export declare const n: bigint;
|
|
45
|
-
export declare const CURVE: {
|
|
46
|
-
p: bigint;
|
|
47
|
-
n: bigint;
|
|
48
|
-
a: bigint;
|
|
49
|
-
b: bigint;
|
|
50
|
-
Gx: bigint;
|
|
51
|
-
Gy: bigint;
|
|
52
|
-
};
|
|
53
|
-
export declare const W3C_DID_V1 = "https://www.w3.org/ns/did/v1";
|
|
54
|
-
export declare const W3C_DID_V1_1 = "https://www.w3.org/TR/did-1.1";
|
|
55
|
-
export declare const W3C_DATA_INTEGRITY_V1 = "https://w3id.org/security/data-integrity/v1";
|
|
56
|
-
export declare const W3C_DATA_INTEGRITY_V2 = "https://w3id.org/security/data-integrity/v2";
|
|
57
|
-
export declare const W3C_SECURITY_V2 = "https://w3id.org/security/v2";
|
|
58
|
-
export declare const BTCR2_METHOD_CONTEXT = "https://btcr2.dev/context/v1";
|
|
59
|
-
export declare const W3C_ZCAP_V1 = "https://w3id.org/zcap/v1";
|
|
60
|
-
export declare const W3C_JSONLD_PATCH_V1 = "https://w3id.org/json-ld-patch/v1";
|
|
61
|
-
export declare const W3C_MULTIKEY_V1 = "https://w3id.org/security/multikey/v1";
|
|
62
|
-
export declare const W3C_DID_RESOLUTION_V1 = "https://w3id.org/did-resolution/v1";
|
|
63
|
-
export declare const CONTEXT_URL_MAP: {
|
|
64
|
-
w3c: {
|
|
65
|
-
did: {
|
|
66
|
-
v1: string;
|
|
67
|
-
v1_1: string;
|
|
68
|
-
};
|
|
69
|
-
didresolution: {
|
|
70
|
-
v1: string;
|
|
71
|
-
};
|
|
72
|
-
security: {
|
|
73
|
-
v2: string;
|
|
74
|
-
};
|
|
75
|
-
dataintegrity: {
|
|
76
|
-
v1: string;
|
|
77
|
-
v2: string;
|
|
78
|
-
};
|
|
79
|
-
zcap: {
|
|
80
|
-
v1: string;
|
|
81
|
-
};
|
|
82
|
-
jsonldpatch: {
|
|
83
|
-
v1: string;
|
|
84
|
-
};
|
|
85
|
-
multikey: {
|
|
86
|
-
v1: string;
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
btcr2: {
|
|
90
|
-
method: {
|
|
91
|
-
v1: string;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
export declare const BTCR2_DID_DOCUMENT_CONTEXT: string[];
|
|
96
|
-
export declare const BTCR2_MULTIKEY_CONTEXT: string[];
|
|
97
|
-
export declare const BTCR2_DID_UPDATE_PAYLOAD_CONTEXT: string[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|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CAAC;AACzD,eAAO,MAAM,YAAY,kCAAmC,CAAC;AAC7D,eAAO,MAAM,qBAAqB,gDAAgD,CAAC;AACnF,eAAO,MAAM,qBAAqB,gDAAgD,CAAC;AACnF,eAAO,MAAM,eAAe,iCAAiC,CAAC;AAC9D,eAAO,MAAM,oBAAoB,iCAAiC,CAAC;AACnE,eAAO,MAAM,WAAW,6BAA6B,CAAC;AACtD,eAAO,MAAM,mBAAmB,sCAAsC,CAAC;AACvE,eAAO,MAAM,eAAe,0CAA0C,CAAC;AACvE,eAAO,MAAM,qBAAqB,uCAAuC,CAAC;AAC1E,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgC3B,CAAC;AAEF,eAAO,MAAM,0BAA0B,UAGtC,CAAC;AAEF,eAAO,MAAM,sBAAsB,UAGlC,CAAC;AAEF,eAAO,MAAM,gCAAgC,UAK5C,CAAC"}
|
package/dist/types/logger.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
export declare enum Env {
|
|
2
|
-
Development = "development",
|
|
3
|
-
Production = "production",
|
|
4
|
-
Test = "test"
|
|
5
|
-
}
|
|
6
|
-
export type Level = 'debug' | 'error' | 'info' | 'log' | 'warn' | 'security';
|
|
7
|
-
export declare const NODE_ENV: Env;
|
|
8
|
-
/**
|
|
9
|
-
* A flexible, feature-rich logger with:
|
|
10
|
-
* - Environment-based filtering
|
|
11
|
-
* - Namespacing
|
|
12
|
-
* - File/line tracing
|
|
13
|
-
* - Timestamps
|
|
14
|
-
* - Colorized output
|
|
15
|
-
* @class Logger
|
|
16
|
-
* @type {Logger}
|
|
17
|
-
*/
|
|
18
|
-
export declare class Logger {
|
|
19
|
-
private levels;
|
|
20
|
-
private namespace?;
|
|
21
|
-
private useColors;
|
|
22
|
-
private static shared;
|
|
23
|
-
/**
|
|
24
|
-
* Creates a new Logger instance.
|
|
25
|
-
* @param {string} namespace - Optional namespace for log messages.
|
|
26
|
-
* @param {Object} options - Configuration options.
|
|
27
|
-
* @param {Level[]} options.levels - Log levels to enable.
|
|
28
|
-
* @param {boolean} options.useColors - Whether to use colored output.
|
|
29
|
-
*/
|
|
30
|
-
constructor(namespace?: string, options?: {
|
|
31
|
-
levels?: Level[];
|
|
32
|
-
useColors?: boolean;
|
|
33
|
-
});
|
|
34
|
-
/**
|
|
35
|
-
* Logs a message with the specified level.
|
|
36
|
-
* @param {Level} level - The log level.
|
|
37
|
-
* @param {unknown} message - The message to log.
|
|
38
|
-
* @param {...unknown[]} args - Additional arguments to log.
|
|
39
|
-
* @returns {void}
|
|
40
|
-
*/
|
|
41
|
-
private _log;
|
|
42
|
-
debug(message?: unknown, ...args: unknown[]): Logger;
|
|
43
|
-
error(message?: unknown, ...args: unknown[]): Logger;
|
|
44
|
-
info(message?: unknown, ...args: unknown[]): Logger;
|
|
45
|
-
warn(message?: unknown, ...args: unknown[]): Logger;
|
|
46
|
-
security(message?: unknown, ...args: unknown[]): Logger;
|
|
47
|
-
log(message?: unknown, ...args: unknown[]): Logger;
|
|
48
|
-
newline(): Logger;
|
|
49
|
-
/**
|
|
50
|
-
* Static methods for convenience (auto-instantiate).
|
|
51
|
-
* These use a shared singleton instance.
|
|
52
|
-
* @param {unknown} message - The message to log.
|
|
53
|
-
* @param {...unknown[]} args - Additional arguments to log.
|
|
54
|
-
* @returns {void}
|
|
55
|
-
*/
|
|
56
|
-
static debug(message?: unknown, ...args: unknown[]): void;
|
|
57
|
-
static error(message?: unknown, ...args: unknown[]): void;
|
|
58
|
-
static info(message?: unknown, ...args: unknown[]): void;
|
|
59
|
-
static warn(message?: unknown, ...args: unknown[]): void;
|
|
60
|
-
static security(message?: unknown, ...args: unknown[]): void;
|
|
61
|
-
static log(message?: unknown, ...args: unknown[]): void;
|
|
62
|
-
static newline(): void;
|
|
63
|
-
private static instance;
|
|
64
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":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O,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIzD,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIzD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIxD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIxD,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI5D,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIvD,MAAM,CAAC,OAAO;IAId,OAAO,CAAC,MAAM,CAAC,QAAQ;CASxB"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility class for set operations.
|
|
3
|
-
* @name SetUtils
|
|
4
|
-
* @class SetUtils
|
|
5
|
-
*/
|
|
6
|
-
export declare class SetUtils {
|
|
7
|
-
/**
|
|
8
|
-
* Compute the set difference without mutating the inputs.
|
|
9
|
-
* @param {Set<T>} left - The left set.
|
|
10
|
-
* @param {Set<T>} right - The right set.
|
|
11
|
-
* @returns {Set<T>} A new set containing elements in `left` that are not in `right`.
|
|
12
|
-
*/
|
|
13
|
-
static difference<T>(left: Set<T>, right: Set<T>): Set<T>;
|
|
14
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../../src/utils/set.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,QAAQ;IACnB;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;CAU1D"}
|
package/src/constants.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { sha256 } from '@noble/hashes/sha2';
|
|
2
|
-
import { bytesToHex } from '@noble/hashes/utils';
|
|
3
|
-
import { Bytes, HashHex } from './types.js';
|
|
4
|
-
|
|
5
|
-
export const OP_RETURN = 0x6a;
|
|
6
|
-
export const OP_PUSH32 = 0x20;
|
|
7
|
-
export const VALID_HRP = ['k', 'x'];
|
|
8
|
-
export const MULTIBASE_URI_PREFIX = 'urn:mb:';
|
|
9
|
-
export const INITIAL_BLOCK_REWARD = 50;
|
|
10
|
-
export const HALVING_INTERVAL = 150;
|
|
11
|
-
export const COINBASE_MATURITY_DELAY = 100;
|
|
12
|
-
export const DEFAULT_POLAR_CONFIG = {
|
|
13
|
-
username : 'polaruser',
|
|
14
|
-
password : 'polarpass',
|
|
15
|
-
host : 'http://127.0.0.1:18443',
|
|
16
|
-
allowDefaultWallet : true,
|
|
17
|
-
version : '28.1.0'
|
|
18
|
-
};
|
|
19
|
-
export const DEFAULT_REST_CONFIG = { host: 'http://localhost:3000' };
|
|
20
|
-
export const DEFAULT_RPC_CONFIG = DEFAULT_POLAR_CONFIG;
|
|
21
|
-
export const DEFAULT_BLOCK_CONFIRMATIONS = 7;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Load a default RPC config, allowing environment overrides to avoid hard-coding credentials/hosts in bundles.
|
|
25
|
-
* @returns {typeof DEFAULT_POLAR_CONFIG} The RPC config.
|
|
26
|
-
*/
|
|
27
|
-
export function getDefaultRpcConfig(): typeof DEFAULT_POLAR_CONFIG {
|
|
28
|
-
return {
|
|
29
|
-
...DEFAULT_POLAR_CONFIG,
|
|
30
|
-
host : process.env.BTCR2_RPC_HOST ?? DEFAULT_POLAR_CONFIG.host,
|
|
31
|
-
username : process.env.BTCR2_RPC_USER ?? DEFAULT_POLAR_CONFIG.username,
|
|
32
|
-
password : process.env.BTCR2_RPC_PASS ?? DEFAULT_POLAR_CONFIG.password,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Fixed public key header bytes per the Data Integrity BIP340 Cryptosuite spec: [0xe7, 0x01] / [231, 1]
|
|
37
|
-
export const BIP340_PUBLIC_KEY_MULTIBASE_PREFIX: Bytes = new Uint8Array([0xe7, 0x01]);
|
|
38
|
-
// Hash of the BIP-340 Multikey prefix
|
|
39
|
-
export const BIP340_PUBLIC_KEY_MULTIBASE_PREFIX_HASH: HashHex = bytesToHex(sha256(BIP340_PUBLIC_KEY_MULTIBASE_PREFIX));
|
|
40
|
-
// Fixed secret key header bytes per the Data Integrity BIP340 Cryptosuite spec: [0x81, 0x26] / [129, 38]
|
|
41
|
-
export const BIP340_SECRET_KEY_MULTIBASE_PREFIX: Bytes = new Uint8Array([0x81, 0x26]);
|
|
42
|
-
// Hash of the BIP-340 Multikey prefix
|
|
43
|
-
export const BIP340_SECRET_KEY_MULTIBASE_PREFIX_HASH: HashHex = bytesToHex(sha256(BIP340_SECRET_KEY_MULTIBASE_PREFIX));
|
|
44
|
-
// curve's field size
|
|
45
|
-
export const B256 = 2n ** 256n;
|
|
46
|
-
// curve's field prime
|
|
47
|
-
export const P = B256 - 0x1000003d1n;
|
|
48
|
-
// curve (group) order
|
|
49
|
-
export const N = B256 - 0x14551231950b75fc4402da1732fc9bebfn;
|
|
50
|
-
// base point x
|
|
51
|
-
export const Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n;
|
|
52
|
-
// base point y
|
|
53
|
-
export const Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;
|
|
54
|
-
// curve parameters
|
|
55
|
-
export const a = 0n;
|
|
56
|
-
export const b = 7n;
|
|
57
|
-
export const p = P;
|
|
58
|
-
export const n = N;
|
|
59
|
-
export const CURVE = {
|
|
60
|
-
p,
|
|
61
|
-
n,
|
|
62
|
-
a,
|
|
63
|
-
b,
|
|
64
|
-
Gx,
|
|
65
|
-
Gy
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const W3C_DID_V1 = 'https://www.w3.org/ns/did/v1';
|
|
69
|
-
export const W3C_DID_V1_1 = 'https://www.w3.org/TR/did-1.1';
|
|
70
|
-
export const W3C_DATA_INTEGRITY_V1 = 'https://w3id.org/security/data-integrity/v1';
|
|
71
|
-
export const W3C_DATA_INTEGRITY_V2 = 'https://w3id.org/security/data-integrity/v2';
|
|
72
|
-
export const W3C_SECURITY_V2 = 'https://w3id.org/security/v2';
|
|
73
|
-
export const BTCR2_METHOD_CONTEXT = 'https://btcr2.dev/context/v1';
|
|
74
|
-
export const W3C_ZCAP_V1 = 'https://w3id.org/zcap/v1';
|
|
75
|
-
export const W3C_JSONLD_PATCH_V1 = 'https://w3id.org/json-ld-patch/v1';
|
|
76
|
-
export const W3C_MULTIKEY_V1 = 'https://w3id.org/security/multikey/v1';
|
|
77
|
-
export const W3C_DID_RESOLUTION_V1 = 'https://w3id.org/did-resolution/v1';
|
|
78
|
-
export const CONTEXT_URL_MAP = {
|
|
79
|
-
w3c : {
|
|
80
|
-
did : {
|
|
81
|
-
v1 : W3C_DID_V1,
|
|
82
|
-
v1_1 : W3C_DID_V1_1,
|
|
83
|
-
},
|
|
84
|
-
didresolution : {
|
|
85
|
-
v1 : W3C_DID_RESOLUTION_V1,
|
|
86
|
-
},
|
|
87
|
-
security : {
|
|
88
|
-
v2 : W3C_SECURITY_V2,
|
|
89
|
-
},
|
|
90
|
-
dataintegrity : {
|
|
91
|
-
v1 : W3C_DATA_INTEGRITY_V1,
|
|
92
|
-
v2 : W3C_DATA_INTEGRITY_V2,
|
|
93
|
-
},
|
|
94
|
-
zcap : {
|
|
95
|
-
v1 : W3C_ZCAP_V1,
|
|
96
|
-
},
|
|
97
|
-
jsonldpatch : {
|
|
98
|
-
v1 : W3C_JSONLD_PATCH_V1,
|
|
99
|
-
},
|
|
100
|
-
multikey : {
|
|
101
|
-
v1 : W3C_MULTIKEY_V1,
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
btcr2 : {
|
|
105
|
-
method : {
|
|
106
|
-
v1 : BTCR2_METHOD_CONTEXT
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export const BTCR2_DID_DOCUMENT_CONTEXT = [
|
|
113
|
-
CONTEXT_URL_MAP.w3c.did.v1_1,
|
|
114
|
-
CONTEXT_URL_MAP.btcr2.method.v1,
|
|
115
|
-
];
|
|
116
|
-
|
|
117
|
-
export const BTCR2_MULTIKEY_CONTEXT = [
|
|
118
|
-
CONTEXT_URL_MAP.w3c.did.v1,
|
|
119
|
-
CONTEXT_URL_MAP.w3c.multikey.v1
|
|
120
|
-
];
|
|
121
|
-
|
|
122
|
-
export const BTCR2_DID_UPDATE_PAYLOAD_CONTEXT = [
|
|
123
|
-
CONTEXT_URL_MAP.btcr2.method.v1,
|
|
124
|
-
CONTEXT_URL_MAP.w3c.security.v2,
|
|
125
|
-
CONTEXT_URL_MAP.w3c.zcap.v1,
|
|
126
|
-
CONTEXT_URL_MAP.w3c.jsonldpatch.v1,
|
|
127
|
-
];
|
package/src/logger.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import chalk, { ChalkInstance } from 'chalk';
|
|
2
|
-
|
|
3
|
-
export enum Env {
|
|
4
|
-
Development = 'development',
|
|
5
|
-
Production = 'production',
|
|
6
|
-
Test = 'test',
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type Level = 'debug' | 'error' | 'info' | 'log' | 'warn' | 'security';
|
|
10
|
-
|
|
11
|
-
export const NODE_ENV = (process.env.NODE_ENV as Env) || Env.Development;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Mapping of log levels to colors for cleaner, more flexible logging.
|
|
15
|
-
*/
|
|
16
|
-
const LOG_LEVELS: Record<Env, Level[]> = {
|
|
17
|
-
development : ['debug', 'info', 'log', 'warn', 'security'],
|
|
18
|
-
test : ['log', 'info', 'error'],
|
|
19
|
-
production : ['error'],
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Colors associated with each log level.
|
|
24
|
-
*/
|
|
25
|
-
const LEVEL_STYLES: Record<Level, ChalkInstance> = {
|
|
26
|
-
debug : chalk.green,
|
|
27
|
-
error : chalk.red,
|
|
28
|
-
info : chalk.blue,
|
|
29
|
-
log : chalk.gray,
|
|
30
|
-
warn : chalk.yellow,
|
|
31
|
-
security : chalk.magenta,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Defines the method mapping for console methods.
|
|
36
|
-
*/
|
|
37
|
-
// eslint-disable-next-line no-undef
|
|
38
|
-
const LEVEL_METHODS: Record<Level, keyof Console> = {
|
|
39
|
-
debug : 'debug',
|
|
40
|
-
error : 'error',
|
|
41
|
-
info : 'info',
|
|
42
|
-
log : 'log',
|
|
43
|
-
warn : 'warn',
|
|
44
|
-
security : 'warn',
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* A flexible, feature-rich logger with:
|
|
49
|
-
* - Environment-based filtering
|
|
50
|
-
* - Namespacing
|
|
51
|
-
* - File/line tracing
|
|
52
|
-
* - Timestamps
|
|
53
|
-
* - Colorized output
|
|
54
|
-
* @class Logger
|
|
55
|
-
* @type {Logger}
|
|
56
|
-
*/
|
|
57
|
-
export class Logger {
|
|
58
|
-
private levels: Level[];
|
|
59
|
-
private namespace?: string;
|
|
60
|
-
private useColors: boolean;
|
|
61
|
-
private static shared: Logger;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Creates a new Logger instance.
|
|
65
|
-
* @param {string} namespace - Optional namespace for log messages.
|
|
66
|
-
* @param {Object} options - Configuration options.
|
|
67
|
-
* @param {Level[]} options.levels - Log levels to enable.
|
|
68
|
-
* @param {boolean} options.useColors - Whether to use colored output.
|
|
69
|
-
*/
|
|
70
|
-
constructor(namespace?: string, options: { levels?: Level[]; useColors?: boolean } = {}) {
|
|
71
|
-
this.levels = options.levels || LOG_LEVELS[NODE_ENV] || [];
|
|
72
|
-
this.namespace = namespace || 'did-btcr2-js';
|
|
73
|
-
const envForce = process.env.LOG_COLORS;
|
|
74
|
-
this.useColors = options.useColors || (envForce ? envForce !== '0' && envForce.toLowerCase() !== 'false' : Boolean(process.stdout.isTTY));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Logs a message with the specified level.
|
|
79
|
-
* @param {Level} level - The log level.
|
|
80
|
-
* @param {unknown} message - The message to log.
|
|
81
|
-
* @param {...unknown[]} args - Additional arguments to log.
|
|
82
|
-
* @returns {void}
|
|
83
|
-
*/
|
|
84
|
-
private _log(level: Level, message?: unknown, ...args: unknown[]): void {
|
|
85
|
-
if (!this.levels.includes(level)) return;
|
|
86
|
-
|
|
87
|
-
const color = LEVEL_STYLES[level];
|
|
88
|
-
const method = LEVEL_METHODS[level];
|
|
89
|
-
|
|
90
|
-
const timestamp = new Date().toISOString();
|
|
91
|
-
const namespace = this.namespace ? `[${this.namespace}]` : '';
|
|
92
|
-
const render = this.useColors ? color : (v: string) => v;
|
|
93
|
-
const renderGray = this.useColors ? chalk.gray : (v: string) => v;
|
|
94
|
-
|
|
95
|
-
(console[method] as (...args: any[]) => void)(
|
|
96
|
-
`${renderGray(timestamp)} ${namespace} ${render(level)}: ${message}`,
|
|
97
|
-
...args
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
debug(message?: unknown, ...args: unknown[]): Logger {
|
|
102
|
-
this._log('debug', message, ...args); return this;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
error(message?: unknown, ...args: unknown[]): Logger {
|
|
106
|
-
this._log('error', message, ...args); return this;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
info(message?: unknown, ...args: unknown[]): Logger {
|
|
110
|
-
this._log('info', message, ...args); return this;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
warn(message?: unknown, ...args: unknown[]): Logger {
|
|
114
|
-
this._log('warn', message, ...args); return this;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
security(message?: unknown, ...args: unknown[]): Logger {
|
|
118
|
-
this._log('security', message, ...args); return this;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
log(message?: unknown, ...args: unknown[]): Logger {
|
|
122
|
-
this._log('log', message, ...args); return this;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
newline(): Logger {
|
|
126
|
-
console.log(); return this;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Static methods for convenience (auto-instantiate).
|
|
131
|
-
* These use a shared singleton instance.
|
|
132
|
-
* @param {unknown} message - The message to log.
|
|
133
|
-
* @param {...unknown[]} args - Additional arguments to log.
|
|
134
|
-
* @returns {void}
|
|
135
|
-
*/
|
|
136
|
-
static debug(message?: unknown, ...args: unknown[]): void {
|
|
137
|
-
Logger.instance().debug(message, ...args);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
static error(message?: unknown, ...args: unknown[]): void {
|
|
141
|
-
Logger.instance().error(message, ...args);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
static info(message?: unknown, ...args: unknown[]): void {
|
|
145
|
-
Logger.instance().info(message, ...args);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
static warn(message?: unknown, ...args: unknown[]): void {
|
|
149
|
-
Logger.instance().warn(message, ...args);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
static security(message?: unknown, ...args: unknown[]): void {
|
|
153
|
-
Logger.instance().security(message, ...args);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
static log(message?: unknown, ...args: unknown[]): void {
|
|
157
|
-
Logger.instance().log(message, ...args);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
static newline() {
|
|
161
|
-
Logger.instance().newline();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private static instance(levels?: Level[], useColors?: boolean): Logger {
|
|
165
|
-
if (!Logger.shared) {
|
|
166
|
-
Logger.shared = new Logger(undefined, { levels, useColors });
|
|
167
|
-
} else {
|
|
168
|
-
if (levels) Logger.shared.levels = levels;
|
|
169
|
-
if (useColors !== undefined) Logger.shared.useColors = useColors;
|
|
170
|
-
}
|
|
171
|
-
return Logger.shared;
|
|
172
|
-
}
|
|
173
|
-
}
|
package/src/utils/set.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility class for set operations.
|
|
3
|
-
* @name SetUtils
|
|
4
|
-
* @class SetUtils
|
|
5
|
-
*/
|
|
6
|
-
export class SetUtils {
|
|
7
|
-
/**
|
|
8
|
-
* Compute the set difference without mutating the inputs.
|
|
9
|
-
* @param {Set<T>} left - The left set.
|
|
10
|
-
* @param {Set<T>} right - The right set.
|
|
11
|
-
* @returns {Set<T>} A new set containing elements in `left` that are not in `right`.
|
|
12
|
-
*/
|
|
13
|
-
static difference<T>(left: Set<T>, right: Set<T>): Set<T> {
|
|
14
|
-
const result = new Set<T>();
|
|
15
|
-
for (const value of left) {
|
|
16
|
-
if (!right.has(value)) {
|
|
17
|
-
result.add(value);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|