@dignetwork/dig-sdk 0.0.1-alpha.191 → 0.0.1-alpha.192
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 +1 -6
- package/dist/utils/Udi.d.ts.map +1 -1
- package/dist/utils/Udi.js +8 -30
- package/package.json +1 -1
package/dist/utils/Udi.d.ts
CHANGED
|
@@ -10,11 +10,8 @@ declare class Udi {
|
|
|
10
10
|
static fromUrn(urn: string): Udi;
|
|
11
11
|
static convertToHex(input: string): string;
|
|
12
12
|
static addBase32Padding(input: string): string;
|
|
13
|
-
|
|
14
|
-
static addBase64Padding(base64: string): string;
|
|
15
|
-
toUrn(encoding?: "hex" | "base32" | "base64"): string;
|
|
13
|
+
toUrn(encoding?: "hex" | "base32"): string;
|
|
16
14
|
private formatBufferAsEncoding;
|
|
17
|
-
static toBase64UrlSafe(base64Standard: string): string;
|
|
18
15
|
equals(other: Udi): boolean;
|
|
19
16
|
toString(): string;
|
|
20
17
|
clone(): Udi;
|
|
@@ -23,8 +20,6 @@ declare class Udi {
|
|
|
23
20
|
get rootHash(): string | null;
|
|
24
21
|
get storeIdBase32(): string;
|
|
25
22
|
get rootHashBase32(): string | null;
|
|
26
|
-
get storeIdBase64(): string;
|
|
27
|
-
get rootHashBase64(): string | null;
|
|
28
23
|
}
|
|
29
24
|
export { Udi };
|
|
30
25
|
//# sourceMappingURL=Udi.d.ts.map
|
package/dist/utils/Udi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Udi.d.ts","sourceRoot":"","sources":["../../src/utils/Udi.ts"],"names":[],"mappings":"AAIA,cAAM,GAAG;IACP,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;IAC7C,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,I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AAQ,GAAE,KAAK,GAAG,QAAgB,GAAG,MAAM;IAmBjD,OAAO,CAAC,sBAAsB;IAa9B,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAW3B,QAAQ,IAAI,MAAM;IAIlB,KAAK,IAAI,GAAG;IASZ,QAAQ,IAAI,MAAM;IAMlB,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,QAAQ,IAAI,MAAM,GAAG,IAAI,CAE5B;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,cAAc,IAAI,MAAM,GAAG,IAAI,CAIlC;CACF;AAED,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
package/dist/utils/Udi.js
CHANGED
|
@@ -66,9 +66,6 @@ class Udi {
|
|
|
66
66
|
return new Udi(chainName, storeIdHex, rootHashHex, resourceKey);
|
|
67
67
|
}
|
|
68
68
|
static convertToHex(input) {
|
|
69
|
-
// Attempt hex conversion first
|
|
70
|
-
if (/^[a-fA-F0-9]{64}$/.test(input))
|
|
71
|
-
return input;
|
|
72
69
|
// Convert from Base32
|
|
73
70
|
try {
|
|
74
71
|
const paddedInput = Udi.addBase32Padding(input.toUpperCase());
|
|
@@ -78,27 +75,18 @@ class Udi {
|
|
|
78
75
|
catch (e) {
|
|
79
76
|
console.warn("Base32 decoding failed, trying Base64 encoding...");
|
|
80
77
|
}
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const buffer = Buffer.from(standardBase64, "base64");
|
|
85
|
-
return buffer.toString("hex");
|
|
78
|
+
// Attempt hex conversion first
|
|
79
|
+
if (/^[a-fA-F0-9]{64}$/.test(input)) {
|
|
80
|
+
return input;
|
|
86
81
|
}
|
|
87
|
-
|
|
88
|
-
throw new Error("
|
|
82
|
+
else {
|
|
83
|
+
throw new Error("Input must be a 64-character hex string.");
|
|
89
84
|
}
|
|
90
85
|
}
|
|
91
86
|
static addBase32Padding(input) {
|
|
92
87
|
const paddingNeeded = (8 - (input.length % 8)) % 8;
|
|
93
88
|
return input + "=".repeat(paddingNeeded);
|
|
94
89
|
}
|
|
95
|
-
static toStandardBase64(base64UrlSafe) {
|
|
96
|
-
return base64UrlSafe.replace(/-/g, "+").replace(/_/g, "/");
|
|
97
|
-
}
|
|
98
|
-
static addBase64Padding(base64) {
|
|
99
|
-
const paddingNeeded = (4 - (base64.length % 4)) % 4;
|
|
100
|
-
return base64 + "=".repeat(paddingNeeded);
|
|
101
|
-
}
|
|
102
90
|
toUrn(encoding = "hex") {
|
|
103
91
|
const storeIdStr = this.formatBufferAsEncoding(this._storeIdHex, encoding);
|
|
104
92
|
let urn = `${Udi.namespace}:${this.chainName}:${storeIdStr}`;
|
|
@@ -119,14 +107,8 @@ class Udi {
|
|
|
119
107
|
else if (encoding === "base32") {
|
|
120
108
|
return (0, hi_base32_1.encode)(buffer).replace(/=+$/, ""); // Strip padding for Base32
|
|
121
109
|
}
|
|
122
|
-
else if (encoding === "base64") {
|
|
123
|
-
return Udi.toBase64UrlSafe(buffer.toString("base64")); // Convert to URL-safe Base64
|
|
124
|
-
}
|
|
125
110
|
throw new Error("Unsupported encoding type");
|
|
126
111
|
}
|
|
127
|
-
static toBase64UrlSafe(base64Standard) {
|
|
128
|
-
return base64Standard.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
129
|
-
}
|
|
130
112
|
equals(other) {
|
|
131
113
|
return (this._storeIdHex === other._storeIdHex &&
|
|
132
114
|
this.chainName === other.chainName &&
|
|
@@ -156,13 +138,9 @@ class Udi {
|
|
|
156
138
|
return this.formatBufferAsEncoding(this._storeIdHex, "base32");
|
|
157
139
|
}
|
|
158
140
|
get rootHashBase32() {
|
|
159
|
-
return this._rootHashHex
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return this.formatBufferAsEncoding(this._storeIdHex, "base64");
|
|
163
|
-
}
|
|
164
|
-
get rootHashBase64() {
|
|
165
|
-
return this._rootHashHex ? this.formatBufferAsEncoding(this._rootHashHex, "base64") : null;
|
|
141
|
+
return this._rootHashHex
|
|
142
|
+
? this.formatBufferAsEncoding(this._rootHashHex, "base32")
|
|
143
|
+
: null;
|
|
166
144
|
}
|
|
167
145
|
}
|
|
168
146
|
exports.Udi = Udi;
|