Skip to content

Commit

Permalink
Merge pull request #38 from iden3/feat/did-to-json
Browse files Browse the repository at this point in the history
add DID toJson function
  • Loading branch information
vmidyllic authored Jun 6, 2024
2 parents 18db381 + 72c1b8c commit 703a4a6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iden3/js-iden3-core",
"version": "1.3.1",
"version": "1.3.2",
"description": "Low level API to create and manipulate iden3 Claims.",
"source": "./src/index.ts",
"types": "dist/types/index.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/did/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export class DID {
return buff.join('');
}

toJSON() {
return this.string();
}

static parse(s: string): DID {
const parser = new Parser(s);

Expand Down
12 changes: 12 additions & 0 deletions tests/did.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ describe('DID tests', () => {
expect('did:iden3:readonly:tJ93RwaVfE1PEMxd5rpZZuPtLCwbEaDCrNBhAy8HM').toBe(did2.string());
});

it('Test DID to JSON', () => {
const didStr = 'did:polygonid:linea:sepolia:32232vGknSaJHfCBffnbzHzYYy6FvHDkK9QL4SFAq6';
const did = DID.parse(didStr);
const field1Val = 'field1';
const objWithDid = {
field1: field1Val,
did
};
const stringify = JSON.stringify(objWithDid);
expect(stringify).toBe(`{"field1":"${field1Val}","did":"${didStr}"}`);
});

describe('TestDID_PolygonID_Types', () => {
const testCases = [
{
Expand Down

0 comments on commit 703a4a6

Please sign in to comment.