Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DID toJson function #38

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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