Skip to content

Commit 2e042e0

Browse files
Merge pull request #172 from DIG-Network/release/v0.0.1-alpha.184
Release/v0.0.1 alpha.184
2 parents 20f4db6 + 2076c5a commit 2e042e0

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [0.0.1-alpha.184](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.183...v0.0.1-alpha.184) (2024-10-31)
6+
7+
8+
### Features
9+
10+
* add base64 getters to udi class ([6596134](https://github.com/DIG-Network/dig-chia-sdk/commit/6596134c5f3207139b846dc28381f50530b61078))
11+
512
### [0.0.1-alpha.183](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.182...v0.0.1-alpha.183) (2024-10-31)
613

714

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/dig-sdk",
3-
"version": "0.0.1-alpha.183",
3+
"version": "0.0.1-alpha.184",
44
"description": "",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/utils/Udi.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ class Udi {
6464
throw new Error("Failed to decode input as a 32-byte buffer.");
6565
}
6666

67+
static fromUrn(urn: string): Udi {
68+
const parsedUrn = urns.parseURN(urn);
69+
if (parsedUrn.nid.toLowerCase() !== Udi.nid) {
70+
throw new Error(`Invalid nid: ${parsedUrn.nid}`);
71+
}
72+
73+
const parts = parsedUrn.nss.split(":");
74+
if (parts.length < 2) {
75+
throw new Error(`Invalid UDI format: ${parsedUrn.nss}`);
76+
}
77+
78+
const chainName = parts[0];
79+
const storeId = Udi.convertToBuffer(parts[1].split("/")[0]);
80+
81+
let rootHash: Buffer | null = null;
82+
if (parts.length > 2) {
83+
rootHash = Udi.convertToBuffer(parts[2].split("/")[0]);
84+
}
85+
86+
const pathParts = parsedUrn.nss.split("/");
87+
let resourceKey: string | null = null;
88+
if (pathParts.length > 1) {
89+
resourceKey = pathParts.slice(1).join("/");
90+
}
91+
92+
return new Udi(chainName, storeId, rootHash, resourceKey);
93+
}
94+
6795
static addBase32Padding(input: string): string {
6896
const paddingNeeded = (8 - (input.length % 8)) % 8;
6997
return input + "=".repeat(paddingNeeded);

0 commit comments

Comments
 (0)