@dignetwork/dig-sdk 0.0.1-alpha.181 → 0.0.1-alpha.182
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/utils/Udi.d.ts +8 -2
- package/dist/utils/Udi.d.ts.map +1 -1
- package/dist/utils/Udi.js +37 -10
- package/package.json +1 -1
package/dist/utils/Udi.d.ts
CHANGED
|
@@ -9,12 +9,16 @@ declare class Udi {
|
|
|
9
9
|
static convertToBuffer(input: string | Buffer): Buffer;
|
|
10
10
|
static isHex(input: string): boolean;
|
|
11
11
|
static isBase32(input: string): boolean;
|
|
12
|
+
static isBase64Safe(input: string): boolean;
|
|
12
13
|
static addBase32Padding(input: string): string;
|
|
14
|
+
static toStandardBase64(base64Safe: string): string;
|
|
15
|
+
static toBase64Safe(base64Standard: string): string;
|
|
16
|
+
static addBase64Padding(base64: string): string;
|
|
13
17
|
withRootHash(rootHash: string | Buffer | null): Udi;
|
|
14
18
|
withResourceKey(resourceKey: string | null): Udi;
|
|
15
19
|
static fromUrn(urn: string): Udi;
|
|
16
|
-
toUrn(encoding?: "hex" | "base32"): string;
|
|
17
|
-
bufferToString(buffer: Buffer, encoding: "hex" | "base32"): string;
|
|
20
|
+
toUrn(encoding?: "hex" | "base32" | "base64"): string;
|
|
21
|
+
bufferToString(buffer: Buffer, encoding: "hex" | "base32" | "base64"): string;
|
|
18
22
|
equals(other: Udi): boolean;
|
|
19
23
|
toString(): string;
|
|
20
24
|
clone(): Udi;
|
|
@@ -23,6 +27,8 @@ declare class Udi {
|
|
|
23
27
|
get rootHash(): string | null;
|
|
24
28
|
get storeIdBase32(): string;
|
|
25
29
|
get rootHashBase32(): string | null;
|
|
30
|
+
get storeIdBase64(): string;
|
|
31
|
+
get rootHashBase64(): string | null;
|
|
26
32
|
}
|
|
27
33
|
export { Udi };
|
|
28
34
|
//# sourceMappingURL=Udi.d.ts.map
|
package/dist/utils/Udi.d.ts.map
CHANGED
|
@@ -1 +1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AAE,GAAG,EAAE,CAAC"}
|
package/dist/utils/Udi.js
CHANGED
|
@@ -46,9 +46,13 @@ class Udi {
|
|
|
46
46
|
}
|
|
47
47
|
if (Udi.isBase32(input)) {
|
|
48
48
|
const paddedInput = Udi.addBase32Padding(input.toUpperCase());
|
|
49
|
-
return Buffer.from((0, hi_base32_1.decode)(paddedInput, false));
|
|
49
|
+
return Buffer.from((0, hi_base32_1.decode)(paddedInput, false));
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
if (Udi.isBase64Safe(input)) {
|
|
52
|
+
const standardBase64 = Udi.addBase64Padding(Udi.toStandardBase64(input));
|
|
53
|
+
return Buffer.from(standardBase64, "base64");
|
|
54
|
+
}
|
|
55
|
+
throw new Error("Invalid input encoding. Must be 32-byte hex, Base32, or Base64 URL-safe string.");
|
|
52
56
|
}
|
|
53
57
|
static isHex(input) {
|
|
54
58
|
return /^[a-fA-F0-9]{64}$/.test(input);
|
|
@@ -56,11 +60,23 @@ class Udi {
|
|
|
56
60
|
static isBase32(input) {
|
|
57
61
|
return /^[a-z2-7]{52}$/.test(input.toLowerCase());
|
|
58
62
|
}
|
|
63
|
+
static isBase64Safe(input) {
|
|
64
|
+
return /^[A-Za-z0-9\-_]+$/.test(input);
|
|
65
|
+
}
|
|
59
66
|
static addBase32Padding(input) {
|
|
60
|
-
// Calculate required padding
|
|
61
67
|
const paddingNeeded = (8 - (input.length % 8)) % 8;
|
|
62
68
|
return input + "=".repeat(paddingNeeded);
|
|
63
69
|
}
|
|
70
|
+
static toStandardBase64(base64Safe) {
|
|
71
|
+
return base64Safe.replace(/-/g, "+").replace(/_/g, "/");
|
|
72
|
+
}
|
|
73
|
+
static toBase64Safe(base64Standard) {
|
|
74
|
+
return base64Standard.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
75
|
+
}
|
|
76
|
+
static addBase64Padding(base64) {
|
|
77
|
+
const paddingNeeded = (4 - (base64.length % 4)) % 4;
|
|
78
|
+
return base64 + "=".repeat(paddingNeeded);
|
|
79
|
+
}
|
|
64
80
|
withRootHash(rootHash) {
|
|
65
81
|
return new Udi(this.chainName, this._storeId, rootHash, this.resourceKey);
|
|
66
82
|
}
|
|
@@ -70,7 +86,7 @@ class Udi {
|
|
|
70
86
|
static fromUrn(urn) {
|
|
71
87
|
const parsedUrn = urns.parseURN(urn);
|
|
72
88
|
if (parsedUrn.nid.toLowerCase() !== Udi.nid) {
|
|
73
|
-
throw new Error(`Invalid
|
|
89
|
+
throw new Error(`Invalid UDI: ${parsedUrn.nid}`);
|
|
74
90
|
}
|
|
75
91
|
const parts = parsedUrn.nss.split(":");
|
|
76
92
|
if (parts.length < 2) {
|
|
@@ -102,9 +118,16 @@ class Udi {
|
|
|
102
118
|
return urn;
|
|
103
119
|
}
|
|
104
120
|
bufferToString(buffer, encoding) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
if (encoding === "hex") {
|
|
122
|
+
return buffer.toString("hex");
|
|
123
|
+
}
|
|
124
|
+
else if (encoding === "base32") {
|
|
125
|
+
return (0, hi_base32_1.encode)(buffer).toLowerCase().replace(/=+$/, "");
|
|
126
|
+
}
|
|
127
|
+
else if (encoding === "base64") {
|
|
128
|
+
return Udi.toBase64Safe(buffer.toString("base64"));
|
|
129
|
+
}
|
|
130
|
+
throw new Error("Unsupported encoding type");
|
|
108
131
|
}
|
|
109
132
|
equals(other) {
|
|
110
133
|
return (this._storeId.equals(other._storeId) &&
|
|
@@ -135,9 +158,13 @@ class Udi {
|
|
|
135
158
|
return this.bufferToString(this._storeId, "base32");
|
|
136
159
|
}
|
|
137
160
|
get rootHashBase32() {
|
|
138
|
-
return this._rootHash
|
|
139
|
-
|
|
140
|
-
|
|
161
|
+
return this._rootHash ? this.bufferToString(this._rootHash, "base32") : null;
|
|
162
|
+
}
|
|
163
|
+
get storeIdBase64() {
|
|
164
|
+
return this.bufferToString(this._storeId, "base64");
|
|
165
|
+
}
|
|
166
|
+
get rootHashBase64() {
|
|
167
|
+
return this._rootHash ? this.bufferToString(this._rootHash, "base64") : null;
|
|
141
168
|
}
|
|
142
169
|
}
|
|
143
170
|
exports.Udi = Udi;
|