Skip to content

Commit

Permalink
Feature/auth-update (#97)
Browse files Browse the repository at this point in the history
* Update JS-sdk

* 1.5.0
  • Loading branch information
Kolezhniuk authored Sep 6, 2024
1 parent 4907314 commit 4ded5f3
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 97 deletions.
218 changes: 161 additions & 57 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iden3/js-iden3-auth",
"version": "1.4.0",
"version": "1.5.0",
"description": "iden3-auth implementation in JavaScript",
"main": "dist/cjs/index.js",
"source": "./src/index.ts",
Expand Down Expand Up @@ -32,12 +32,12 @@
"url": "https://github.com/iden3/js-iden3-auth"
},
"dependencies": {
"@0xpolygonid/js-sdk": "1.18.3",
"@iden3/js-crypto": "1.1.0",
"@0xpolygonid/js-sdk": "1.16.1",
"@iden3/js-iden3-core": "1.4.0",
"@iden3/js-jsonld-merklization": "1.3.1",
"@iden3/js-jwz": "1.6.0",
"@iden3/js-merkletree": "1.2.0",
"@iden3/js-jsonld-merklization": "1.4.1",
"@iden3/js-jwz": "1.7.1",
"@iden3/js-merkletree": "1.3.1",
"did-resolver": "^4.1.0",
"ethers": "^5.4.0",
"tslib": "^2.6.2",
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class Verifier {
const pubSignals = await verifier.verifyQuery(
proofRequest.query as unknown as Query,
this.schemaLoader,
proofResp.vp as JSON,
proofResp.vp,
opts,
params
);
Expand Down
5 changes: 3 additions & 2 deletions src/circuits/atomicMtpV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
AtomicQueryMTPV2PubSignals,
BaseConfig,
byteEncoder,
CircuitId
CircuitId,
VerifiablePresentation
} from '@0xpolygonid/js-sdk';

const valuesSize = 64;
Expand Down Expand Up @@ -41,7 +42,7 @@ export class AtomicQueryMTPV2PubSignalsVerifier
async verifyQuery(
query: Query,
schemaLoader?: DocumentLoader,
verifiablePresentation?: JSON,
verifiablePresentation?: VerifiablePresentation,
opts?: VerifyOpts
): Promise<BaseConfig> {
const outs: ClaimOutputs = {
Expand Down
5 changes: 3 additions & 2 deletions src/circuits/atomicSigV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
AtomicQuerySigV2PubSignals,
BaseConfig,
byteEncoder,
CircuitId
CircuitId,
VerifiablePresentation
} from '@0xpolygonid/js-sdk';

const valuesSize = 64;
Expand All @@ -34,7 +35,7 @@ export class AtomicQuerySigV2PubSignalsVerifier
async verifyQuery(
query: Query,
schemaLoader?: DocumentLoader,
verifiablePresentation?: JSON,
verifiablePresentation?: VerifiablePresentation,
opts?: VerifyOpts
): Promise<BaseConfig> {
const outs: ClaimOutputs = {
Expand Down
10 changes: 4 additions & 6 deletions src/circuits/atomicV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
validateDisclosureNativeSDSupport,
validateEmptyCredentialSubjectNoopNativeSupport,
validateOperators,
VerifiablePresentation,
verifyFieldValueInclusionNativeExistsSupport
} from '@0xpolygonid/js-sdk';
import { JsonLd } from 'jsonld/jsonld-spec';
Expand All @@ -30,10 +31,7 @@ const defaultProofVerifyOpts = 1 * 60 * 60 * 1000; // 1 hour
* Verifies the public signals for the AtomicQueryV3 circuit.
* @beta
*/
export class AtomicQueryV3PubSignalsVerifier
extends IDOwnershipPubSignals
implements PubSignalsVerifier
{
export class AtomicQueryV3PubSignalsVerifier extends IDOwnershipPubSignals implements PubSignalsVerifier {
pubSignals = new AtomicQueryV3PubSignals();

constructor(pubSignals: string[]) {
Expand All @@ -49,7 +47,7 @@ export class AtomicQueryV3PubSignalsVerifier
async verifyQuery(
query: Query,
schemaLoader?: DocumentLoader,
verifiablePresentation?: JSON,
verifiablePresentation?: VerifiablePresentation,
opts?: VerifyOpts,
params?: JSONObject
): Promise<BaseConfig> {
Expand Down Expand Up @@ -84,7 +82,7 @@ export class AtomicQueryV3PubSignalsVerifier
const queriesMetadata = await parseQueriesMetadata(
query.type,
JSON.stringify(context),
query.credentialSubject as JSONObject,
query.credentialSubject,
{
documentLoader: loader
}
Expand Down
8 changes: 4 additions & 4 deletions src/circuits/linkedMultiQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
QueryMetadata,
LinkedMultiQueryInputs,
Operators,
fieldValueFromVerifiablePresentation
fieldValueFromVerifiablePresentation,
VerifiablePresentation
} from '@0xpolygonid/js-sdk';
import { poseidon } from '@iden3/js-crypto';

/**
* Verifies the linked multi-query circuit.
Expand All @@ -38,7 +38,7 @@ export class LinkedMultiQueryVerifier implements PubSignalsVerifier {
async verifyQuery(
query: Query,
schemaLoader?: DocumentLoader,
verifiablePresentation?: JSON
verifiablePresentation?: VerifiablePresentation
): Promise<BaseConfig> {
let schema: JSONObject;
const ldOpts = { documentLoader: schemaLoader ?? cacheLoader() };
Expand All @@ -48,7 +48,7 @@ export class LinkedMultiQueryVerifier implements PubSignalsVerifier {
throw new Error(`can't load schema for request query`);
}
const ldContextJSON = JSON.stringify(schema);
const credentialSubject = query.credentialSubject as JSONObject;
const credentialSubject = query.credentialSubject;
const schemaId: string = await Path.getTypeIDFromContext(ldContextJSON, query.type, ldOpts);
const schemaHash = calculateCoreSchemaHash(byteEncoder.encode(schemaId));

Expand Down
11 changes: 6 additions & 5 deletions src/circuits/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
CircuitId,
ProofQuery,
parseQueriesMetadata,
JSONObject,
checkQueryRequest,
validateDisclosureV2Circuit,
validateEmptyCredentialSubjectV2Circuit,
verifyFieldValueInclusionV2,
validateOperators,
checkCircuitOperator
checkCircuitOperator,
JsonDocumentObject,
VerifiablePresentation
} from '@0xpolygonid/js-sdk';
import { VerifyOpts } from './registry';
import { JsonLd } from 'jsonld/jsonld-spec';
Expand All @@ -22,7 +23,7 @@ export const userStateError = new Error(`user state is not valid`);
// Query is a query to circuit
export interface Query {
allowedIssuers: string[];
credentialSubject: { [key: string]: unknown };
credentialSubject: JsonDocumentObject;
context: string;
type: string;
claimID?: string;
Expand Down Expand Up @@ -53,7 +54,7 @@ export async function checkQueryV2Circuits(
outs: ClaimOutputs,
schemaLoader: DocumentLoader | undefined,
opts: VerifyOpts | undefined,
verifiablePresentation: JSON | undefined
verifiablePresentation: VerifiablePresentation | undefined
) {
if (!query.type) {
throw new Error(`proof query type is undefined`);
Expand All @@ -72,7 +73,7 @@ export async function checkQueryV2Circuits(
const queriesMetadata = await parseQueriesMetadata(
query.type,
JSON.stringify(context),
query.credentialSubject as JSONObject,
query.credentialSubject as JsonDocumentObject,
{
documentLoader: loader
}
Expand Down
4 changes: 2 additions & 2 deletions src/circuits/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Query } from '@lib/circuits/query';
import { Resolvers } from '@lib/state/resolver';
import { DocumentLoader } from '@iden3/js-jsonld-merklization';
import { AtomicQueryV3PubSignalsVerifier } from '@lib/circuits/atomicV3';
import { BaseConfig } from '@0xpolygonid/js-sdk';
import { BaseConfig, VerifiablePresentation } from '@0xpolygonid/js-sdk';
import { LinkedMultiQueryVerifier } from '@lib/circuits/linkedMultiQuery';

export type VerifyOpts = {
Expand All @@ -19,7 +19,7 @@ export interface PubSignalsVerifier {
verifyQuery(
query: Query,
schemaLoader?: DocumentLoader,
verifiablePresentation?: JSON,
verifiablePresentation?: VerifiablePresentation,
opts?: VerifyOpts,
circuitParams?: { [key: string]: unknown }
): Promise<BaseConfig>;
Expand Down
20 changes: 10 additions & 10 deletions test/atomicV3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('atomicV3', () => {
const request: AuthorizationRequestMessage = {
id: '28b15cd4-3aa1-4ddc-88a3-c05a0f788065',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/request',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE,
thid: '28b15cd4-3aa1-4ddc-88a3-c05a0f788065',
body: {
callbackUrl: 'https://test.com/callback',
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('atomicV3', () => {
const message: AuthorizationResponseMessage = {
id: '59fbefd2-39ce-4346-94f1-49ec86141ba9',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/response',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,
thid: '28b15cd4-3aa1-4ddc-88a3-c05a0f788065',
body: {
message: 'message to sign',
Expand Down Expand Up @@ -183,10 +183,10 @@ describe('atomicV3', () => {
});

it('TestVerifyV3MessageWithMtpProof_Merklized', async () => {
const request = {
const request: AuthorizationRequestMessage = {
id: '7e5b5847-b479-4499-90ee-5fe4826a5bdd',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/request',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE,
thid: '7e5b5847-b479-4499-90ee-5fe4826a5bdd',
body: {
callbackUrl: 'https://test.com/callback',
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('atomicV3', () => {
const message: AuthorizationResponseMessage = {
id: 'ac381820-21af-499a-8c5d-8f01fca9783c',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/response',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,
thid: '7e5b5847-b479-4499-90ee-5fe4826a5bdd',
body: {
message: 'message to sign',
Expand Down Expand Up @@ -352,7 +352,7 @@ describe('atomicV3', () => {
const request: AuthorizationRequestMessage = {
id: '7d22275a-b518-45bb-8ee1-85e12abd8532',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/request',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE,
thid: '7d22275a-b518-45bb-8ee1-85e12abd8532',
body: {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('atomicV3', () => {
const request = {
id: '7e5b5847-b479-4499-90ee-5fe4826a5bdd',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/request',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE,
thid: '7e5b5847-b479-4499-90ee-5fe4826a5bdd',
body: {
callbackUrl: 'https://test.com/callback',
Expand All @@ -446,7 +446,7 @@ describe('atomicV3', () => {
const message: AuthorizationResponseMessage = {
id: 'ac381820-21af-499a-8c5d-8f01fca9783c',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/response',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,
thid: '7e5b5847-b479-4499-90ee-5fe4826a5bdd',
body: {
scope: [
Expand Down Expand Up @@ -581,7 +581,7 @@ describe('atomicV3', () => {
const request = {
id: '7e5b5847-b479-4499-90ee-5fe4826a5bdd',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/request',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE,
thid: '7e5b5847-b479-4499-90ee-5fe4826a5bdd',
body: {
callbackUrl: 'https://test.com/callback',
Expand All @@ -606,7 +606,7 @@ describe('atomicV3', () => {
const message: AuthorizationResponseMessage = {
id: 'ac381820-21af-499a-8c5d-8f01fca9783c',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/response',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,
thid: '7e5b5847-b479-4499-90ee-5fe4826a5bdd',
body: {
scope: [
Expand Down
4 changes: 2 additions & 2 deletions test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('auth tests', () => {
const response: AuthorizationResponseMessage = {
id: 'd61ca0e1-0fb4-42e1-9baf-10926d76588a',
typ: PROTOCOL_CONSTANTS.MediaType.ZKPMessage,
type: 'https://iden3-communication.io/authorization/1.0/response',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,
thid: '3bfc628a-6d16-4af7-8358-59656ca30600',
body: {
message: 'message to sign',
Expand Down Expand Up @@ -297,7 +297,7 @@ describe('auth tests', () => {
const response: AuthorizationResponseMessage = {
id: 'fe05a780-3a91-4a12-84bd-a23223004543',
typ: PROTOCOL_CONSTANTS.MediaType.ZKPMessage,
type: 'https://iden3-communication.io/authorization/1.0/response',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,
thid: 'cbeb7e95-49a6-4107-ad5d-33de4620a2c7',
body: {
message: 'message to sign',
Expand Down
2 changes: 1 addition & 1 deletion test/linked-proofs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Linked proofs verification', () => {
const authRequest: AuthorizationRequestMessage = {
id: 'f5bcdfc9-3819-4052-ad97-c059119e563c',
typ: PROTOCOL_CONSTANTS.MediaType.PlainMessage,
type: 'https://iden3-communication.io/authorization/1.0/request',
type: PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE,
thid: 'f5bcdfc9-3819-4052-ad97-c059119e563c',
body: {
callbackUrl: 'http://localhost:8080/callback?id=1234442-123123-123123',
Expand Down

0 comments on commit 4ded5f3

Please sign in to comment.