diff --git a/libs/generated/ssi/client/enums.ts b/libs/generated/ssi/client/enums.ts new file mode 100644 index 0000000..d52051c --- /dev/null +++ b/libs/generated/ssi/client/enums.ts @@ -0,0 +1,213 @@ +/* eslint-disable */ + +export const protobufPackage = "hypersign.ssi.client"; + +/** The messages defined here are meant only meant for TS client. */ + +export enum VerificationMethodRelationships { + authentication = "authentication", + assertionMethod = "assertionMethod", + keyAgreement = "keyAgreement", + capabilityInvocation = "capabilityInvocation", + capabilityDelegation = "capabilityDelegation", +} + +export function verificationMethodRelationshipsFromJSON(object: any): VerificationMethodRelationships { + switch (object) { + case 0: + case "authentication": + return VerificationMethodRelationships.authentication; + case 1: + case "assertionMethod": + return VerificationMethodRelationships.assertionMethod; + case 2: + case "keyAgreement": + return VerificationMethodRelationships.keyAgreement; + case 3: + case "capabilityInvocation": + return VerificationMethodRelationships.capabilityInvocation; + case 4: + case "capabilityDelegation": + return VerificationMethodRelationships.capabilityDelegation; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum VerificationMethodRelationships"); + } +} + +export function verificationMethodRelationshipsToJSON(object: VerificationMethodRelationships): string { + switch (object) { + case VerificationMethodRelationships.authentication: + return "authentication"; + case VerificationMethodRelationships.assertionMethod: + return "assertionMethod"; + case VerificationMethodRelationships.keyAgreement: + return "keyAgreement"; + case VerificationMethodRelationships.capabilityInvocation: + return "capabilityInvocation"; + case VerificationMethodRelationships.capabilityDelegation: + return "capabilityDelegation"; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum VerificationMethodRelationships"); + } +} + +export function verificationMethodRelationshipsToNumber(object: VerificationMethodRelationships): number { + switch (object) { + case VerificationMethodRelationships.authentication: + return 0; + case VerificationMethodRelationships.assertionMethod: + return 1; + case VerificationMethodRelationships.keyAgreement: + return 2; + case VerificationMethodRelationships.capabilityInvocation: + return 3; + case VerificationMethodRelationships.capabilityDelegation: + return 4; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum VerificationMethodRelationships"); + } +} + +export enum VerificationMethodTypes { + Ed25519VerificationKey2020 = "Ed25519VerificationKey2020", + EcdsaSecp256k1VerificationKey2019 = "EcdsaSecp256k1VerificationKey2019", + EcdsaSecp256k1RecoveryMethod2020 = "EcdsaSecp256k1RecoveryMethod2020", + X25519KeyAgreementKey2020 = "X25519KeyAgreementKey2020", + X25519KeyAgreementKeyEIP5630 = "X25519KeyAgreementKeyEIP5630", + Bls12381G2Key2020 = "Bls12381G2Key2020", + BabyJubJubVerificationKey2023 = "BabyJubJubVerificationKey2023", +} + +export function verificationMethodTypesFromJSON(object: any): VerificationMethodTypes { + switch (object) { + case 0: + case "Ed25519VerificationKey2020": + return VerificationMethodTypes.Ed25519VerificationKey2020; + case 1: + case "EcdsaSecp256k1VerificationKey2019": + return VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019; + case 2: + case "EcdsaSecp256k1RecoveryMethod2020": + return VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020; + case 3: + case "X25519KeyAgreementKey2020": + return VerificationMethodTypes.X25519KeyAgreementKey2020; + case 4: + case "X25519KeyAgreementKeyEIP5630": + return VerificationMethodTypes.X25519KeyAgreementKeyEIP5630; + case 5: + case "Bls12381G2Key2020": + return VerificationMethodTypes.Bls12381G2Key2020; + case 6: + case "BabyJubJubVerificationKey2023": + return VerificationMethodTypes.BabyJubJubVerificationKey2023; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum VerificationMethodTypes"); + } +} + +export function verificationMethodTypesToJSON(object: VerificationMethodTypes): string { + switch (object) { + case VerificationMethodTypes.Ed25519VerificationKey2020: + return "Ed25519VerificationKey2020"; + case VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019: + return "EcdsaSecp256k1VerificationKey2019"; + case VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020: + return "EcdsaSecp256k1RecoveryMethod2020"; + case VerificationMethodTypes.X25519KeyAgreementKey2020: + return "X25519KeyAgreementKey2020"; + case VerificationMethodTypes.X25519KeyAgreementKeyEIP5630: + return "X25519KeyAgreementKeyEIP5630"; + case VerificationMethodTypes.Bls12381G2Key2020: + return "Bls12381G2Key2020"; + case VerificationMethodTypes.BabyJubJubVerificationKey2023: + return "BabyJubJubVerificationKey2023"; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum VerificationMethodTypes"); + } +} + +export function verificationMethodTypesToNumber(object: VerificationMethodTypes): number { + switch (object) { + case VerificationMethodTypes.Ed25519VerificationKey2020: + return 0; + case VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019: + return 1; + case VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020: + return 2; + case VerificationMethodTypes.X25519KeyAgreementKey2020: + return 3; + case VerificationMethodTypes.X25519KeyAgreementKeyEIP5630: + return 4; + case VerificationMethodTypes.Bls12381G2Key2020: + return 5; + case VerificationMethodTypes.BabyJubJubVerificationKey2023: + return 6; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum VerificationMethodTypes"); + } +} + +export enum ProofTypes { + Ed25519Signature2020 = "Ed25519Signature2020", + EcdsaSecp256k1Signature2019 = "EcdsaSecp256k1Signature2019", + EcdsaSecp256k1RecoverySignature2020 = "EcdsaSecp256k1RecoverySignature2020", + BabyJubJubSignature2023 = "BabyJubJubSignature2023", + BbsBlsSignature2020 = "BbsBlsSignature2020", +} + +export function proofTypesFromJSON(object: any): ProofTypes { + switch (object) { + case 0: + case "Ed25519Signature2020": + return ProofTypes.Ed25519Signature2020; + case 1: + case "EcdsaSecp256k1Signature2019": + return ProofTypes.EcdsaSecp256k1Signature2019; + case 2: + case "EcdsaSecp256k1RecoverySignature2020": + return ProofTypes.EcdsaSecp256k1RecoverySignature2020; + case 3: + case "BabyJubJubSignature2023": + return ProofTypes.BabyJubJubSignature2023; + case 4: + case "BbsBlsSignature2020": + return ProofTypes.BbsBlsSignature2020; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum ProofTypes"); + } +} + +export function proofTypesToJSON(object: ProofTypes): string { + switch (object) { + case ProofTypes.Ed25519Signature2020: + return "Ed25519Signature2020"; + case ProofTypes.EcdsaSecp256k1Signature2019: + return "EcdsaSecp256k1Signature2019"; + case ProofTypes.EcdsaSecp256k1RecoverySignature2020: + return "EcdsaSecp256k1RecoverySignature2020"; + case ProofTypes.BabyJubJubSignature2023: + return "BabyJubJubSignature2023"; + case ProofTypes.BbsBlsSignature2020: + return "BbsBlsSignature2020"; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum ProofTypes"); + } +} + +export function proofTypesToNumber(object: ProofTypes): number { + switch (object) { + case ProofTypes.Ed25519Signature2020: + return 0; + case ProofTypes.EcdsaSecp256k1Signature2019: + return 1; + case ProofTypes.EcdsaSecp256k1RecoverySignature2020: + return 2; + case ProofTypes.BabyJubJubSignature2023: + return 3; + case ProofTypes.BbsBlsSignature2020: + return 4; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum ProofTypes"); + } +} diff --git a/libs/generated/ssi/client_spec.ts b/libs/generated/ssi/client_spec.ts new file mode 100644 index 0000000..ebbc453 --- /dev/null +++ b/libs/generated/ssi/client_spec.ts @@ -0,0 +1,51 @@ +/* eslint-disable */ + +export const protobufPackage = "hypersign.ssi.v1"; + +export enum ClientSpecType { + CLIENT_SPEC_TYPE_NONE = "CLIENT_SPEC_TYPE_NONE", + CLIENT_SPEC_TYPE_COSMOS_ADR036 = "CLIENT_SPEC_TYPE_COSMOS_ADR036", + CLIENT_SPEC_TYPE_ETH_PERSONAL_SIGN = "CLIENT_SPEC_TYPE_ETH_PERSONAL_SIGN", +} + +export function clientSpecTypeFromJSON(object: any): ClientSpecType { + switch (object) { + case 0: + case "CLIENT_SPEC_TYPE_NONE": + return ClientSpecType.CLIENT_SPEC_TYPE_NONE; + case 1: + case "CLIENT_SPEC_TYPE_COSMOS_ADR036": + return ClientSpecType.CLIENT_SPEC_TYPE_COSMOS_ADR036; + case 2: + case "CLIENT_SPEC_TYPE_ETH_PERSONAL_SIGN": + return ClientSpecType.CLIENT_SPEC_TYPE_ETH_PERSONAL_SIGN; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum ClientSpecType"); + } +} + +export function clientSpecTypeToJSON(object: ClientSpecType): string { + switch (object) { + case ClientSpecType.CLIENT_SPEC_TYPE_NONE: + return "CLIENT_SPEC_TYPE_NONE"; + case ClientSpecType.CLIENT_SPEC_TYPE_COSMOS_ADR036: + return "CLIENT_SPEC_TYPE_COSMOS_ADR036"; + case ClientSpecType.CLIENT_SPEC_TYPE_ETH_PERSONAL_SIGN: + return "CLIENT_SPEC_TYPE_ETH_PERSONAL_SIGN"; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum ClientSpecType"); + } +} + +export function clientSpecTypeToNumber(object: ClientSpecType): number { + switch (object) { + case ClientSpecType.CLIENT_SPEC_TYPE_NONE: + return 0; + case ClientSpecType.CLIENT_SPEC_TYPE_COSMOS_ADR036: + return 1; + case ClientSpecType.CLIENT_SPEC_TYPE_ETH_PERSONAL_SIGN: + return 2; + default: + throw new globalThis.Error("Unrecognized enum value " + object + " for enum ClientSpecType"); + } +} diff --git a/libs/generated/ssi/credential.ts b/libs/generated/ssi/credential.ts deleted file mode 100644 index ee85a38..0000000 --- a/libs/generated/ssi/credential.ts +++ /dev/null @@ -1,577 +0,0 @@ -/* eslint-disable */ -import { Writer, Reader } from "protobufjs/minimal"; - -export const protobufPackage = "hypersignprotocol.hidnode.ssi"; - -export interface Claim { - id: string; - currentStatus: string; - statusReason: string; -} - -export interface CredentialStatus { - claim: Claim | undefined; - issuer: string; - issuanceDate: string; - expirationDate: string; - credentialHash: string; -} - -export interface CredentialProof { - type: string; - created: string; - updated: string; - verificationMethod: string; - proofPurpose: string; - proofValue: string; -} - -export interface Credential { - claim: Claim | undefined; - issuer: string; - issuanceDate: string; - expirationDate: string; - credentialHash: string; - proof: CredentialProof | undefined; -} - -const baseClaim: object = { id: "", currentStatus: "", statusReason: "" }; - -export const Claim = { - encode(message: Claim, writer: Writer = Writer.create()): Writer { - if (message.id !== "") { - writer.uint32(10).string(message.id); - } - if (message.currentStatus !== "") { - writer.uint32(18).string(message.currentStatus); - } - if (message.statusReason !== "") { - writer.uint32(26).string(message.statusReason); - } - return writer; - }, - - decode(input: Reader | Uint8Array, length?: number): Claim { - const reader = input instanceof Uint8Array ? new Reader(input) : input; - let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseClaim } as Claim; - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.id = reader.string(); - break; - case 2: - message.currentStatus = reader.string(); - break; - case 3: - message.statusReason = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): Claim { - const message = { ...baseClaim } as Claim; - if (object.id !== undefined && object.id !== null) { - message.id = String(object.id); - } else { - message.id = ""; - } - if (object.currentStatus !== undefined && object.currentStatus !== null) { - message.currentStatus = String(object.currentStatus); - } else { - message.currentStatus = ""; - } - if (object.statusReason !== undefined && object.statusReason !== null) { - message.statusReason = String(object.statusReason); - } else { - message.statusReason = ""; - } - return message; - }, - - toJSON(message: Claim): unknown { - const obj: any = {}; - message.id !== undefined && (obj.id = message.id); - message.currentStatus !== undefined && - (obj.currentStatus = message.currentStatus); - message.statusReason !== undefined && - (obj.statusReason = message.statusReason); - return obj; - }, - - fromPartial(object: DeepPartial): Claim { - const message = { ...baseClaim } as Claim; - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = ""; - } - if (object.currentStatus !== undefined && object.currentStatus !== null) { - message.currentStatus = object.currentStatus; - } else { - message.currentStatus = ""; - } - if (object.statusReason !== undefined && object.statusReason !== null) { - message.statusReason = object.statusReason; - } else { - message.statusReason = ""; - } - return message; - }, -}; - -const baseCredentialStatus: object = { - issuer: "", - issuanceDate: "", - expirationDate: "", - credentialHash: "", -}; - -export const CredentialStatus = { - encode(message: CredentialStatus, writer: Writer = Writer.create()): Writer { - if (message.claim !== undefined) { - Claim.encode(message.claim, writer.uint32(10).fork()).ldelim(); - } - if (message.issuer !== "") { - writer.uint32(18).string(message.issuer); - } - if (message.issuanceDate !== "") { - writer.uint32(26).string(message.issuanceDate); - } - if (message.expirationDate !== "") { - writer.uint32(34).string(message.expirationDate); - } - if (message.credentialHash !== "") { - writer.uint32(42).string(message.credentialHash); - } - return writer; - }, - - decode(input: Reader | Uint8Array, length?: number): CredentialStatus { - const reader = input instanceof Uint8Array ? new Reader(input) : input; - let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseCredentialStatus } as CredentialStatus; - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.claim = Claim.decode(reader, reader.uint32()); - break; - case 2: - message.issuer = reader.string(); - break; - case 3: - message.issuanceDate = reader.string(); - break; - case 4: - message.expirationDate = reader.string(); - break; - case 5: - message.credentialHash = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): CredentialStatus { - const message = { ...baseCredentialStatus } as CredentialStatus; - if (object.claim !== undefined && object.claim !== null) { - message.claim = Claim.fromJSON(object.claim); - } else { - message.claim = undefined; - } - if (object.issuer !== undefined && object.issuer !== null) { - message.issuer = String(object.issuer); - } else { - message.issuer = ""; - } - if (object.issuanceDate !== undefined && object.issuanceDate !== null) { - message.issuanceDate = String(object.issuanceDate); - } else { - message.issuanceDate = ""; - } - if (object.expirationDate !== undefined && object.expirationDate !== null) { - message.expirationDate = String(object.expirationDate); - } else { - message.expirationDate = ""; - } - if (object.credentialHash !== undefined && object.credentialHash !== null) { - message.credentialHash = String(object.credentialHash); - } else { - message.credentialHash = ""; - } - return message; - }, - - toJSON(message: CredentialStatus): unknown { - const obj: any = {}; - message.claim !== undefined && - (obj.claim = message.claim ? Claim.toJSON(message.claim) : undefined); - message.issuer !== undefined && (obj.issuer = message.issuer); - message.issuanceDate !== undefined && - (obj.issuanceDate = message.issuanceDate); - message.expirationDate !== undefined && - (obj.expirationDate = message.expirationDate); - message.credentialHash !== undefined && - (obj.credentialHash = message.credentialHash); - return obj; - }, - - fromPartial(object: DeepPartial): CredentialStatus { - const message = { ...baseCredentialStatus } as CredentialStatus; - if (object.claim !== undefined && object.claim !== null) { - message.claim = Claim.fromPartial(object.claim); - } else { - message.claim = undefined; - } - if (object.issuer !== undefined && object.issuer !== null) { - message.issuer = object.issuer; - } else { - message.issuer = ""; - } - if (object.issuanceDate !== undefined && object.issuanceDate !== null) { - message.issuanceDate = object.issuanceDate; - } else { - message.issuanceDate = ""; - } - if (object.expirationDate !== undefined && object.expirationDate !== null) { - message.expirationDate = object.expirationDate; - } else { - message.expirationDate = ""; - } - if (object.credentialHash !== undefined && object.credentialHash !== null) { - message.credentialHash = object.credentialHash; - } else { - message.credentialHash = ""; - } - return message; - }, -}; - -const baseCredentialProof: object = { - type: "", - created: "", - updated: "", - verificationMethod: "", - proofPurpose: "", - proofValue: "", -}; - -export const CredentialProof = { - encode(message: CredentialProof, writer: Writer = Writer.create()): Writer { - if (message.type !== "") { - writer.uint32(10).string(message.type); - } - if (message.created !== "") { - writer.uint32(18).string(message.created); - } - if (message.updated !== "") { - writer.uint32(26).string(message.updated); - } - if (message.verificationMethod !== "") { - writer.uint32(34).string(message.verificationMethod); - } - if (message.proofPurpose !== "") { - writer.uint32(42).string(message.proofPurpose); - } - if (message.proofValue !== "") { - writer.uint32(50).string(message.proofValue); - } - return writer; - }, - - decode(input: Reader | Uint8Array, length?: number): CredentialProof { - const reader = input instanceof Uint8Array ? new Reader(input) : input; - let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseCredentialProof } as CredentialProof; - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.type = reader.string(); - break; - case 2: - message.created = reader.string(); - break; - case 3: - message.updated = reader.string(); - break; - case 4: - message.verificationMethod = reader.string(); - break; - case 5: - message.proofPurpose = reader.string(); - break; - case 6: - message.proofValue = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): CredentialProof { - const message = { ...baseCredentialProof } as CredentialProof; - if (object.type !== undefined && object.type !== null) { - message.type = String(object.type); - } else { - message.type = ""; - } - if (object.created !== undefined && object.created !== null) { - message.created = String(object.created); - } else { - message.created = ""; - } - if (object.updated !== undefined && object.updated !== null) { - message.updated = String(object.updated); - } else { - message.updated = ""; - } - if ( - object.verificationMethod !== undefined && - object.verificationMethod !== null - ) { - message.verificationMethod = String(object.verificationMethod); - } else { - message.verificationMethod = ""; - } - if (object.proofPurpose !== undefined && object.proofPurpose !== null) { - message.proofPurpose = String(object.proofPurpose); - } else { - message.proofPurpose = ""; - } - if (object.proofValue !== undefined && object.proofValue !== null) { - message.proofValue = String(object.proofValue); - } else { - message.proofValue = ""; - } - return message; - }, - - toJSON(message: CredentialProof): unknown { - const obj: any = {}; - message.type !== undefined && (obj.type = message.type); - message.created !== undefined && (obj.created = message.created); - message.updated !== undefined && (obj.updated = message.updated); - message.verificationMethod !== undefined && - (obj.verificationMethod = message.verificationMethod); - message.proofPurpose !== undefined && - (obj.proofPurpose = message.proofPurpose); - message.proofValue !== undefined && (obj.proofValue = message.proofValue); - return obj; - }, - - fromPartial(object: DeepPartial): CredentialProof { - const message = { ...baseCredentialProof } as CredentialProof; - if (object.type !== undefined && object.type !== null) { - message.type = object.type; - } else { - message.type = ""; - } - if (object.created !== undefined && object.created !== null) { - message.created = object.created; - } else { - message.created = ""; - } - if (object.updated !== undefined && object.updated !== null) { - message.updated = object.updated; - } else { - message.updated = ""; - } - if ( - object.verificationMethod !== undefined && - object.verificationMethod !== null - ) { - message.verificationMethod = object.verificationMethod; - } else { - message.verificationMethod = ""; - } - if (object.proofPurpose !== undefined && object.proofPurpose !== null) { - message.proofPurpose = object.proofPurpose; - } else { - message.proofPurpose = ""; - } - if (object.proofValue !== undefined && object.proofValue !== null) { - message.proofValue = object.proofValue; - } else { - message.proofValue = ""; - } - return message; - }, -}; - -const baseCredential: object = { - issuer: "", - issuanceDate: "", - expirationDate: "", - credentialHash: "", -}; - -export const Credential = { - encode(message: Credential, writer: Writer = Writer.create()): Writer { - if (message.claim !== undefined) { - Claim.encode(message.claim, writer.uint32(10).fork()).ldelim(); - } - if (message.issuer !== "") { - writer.uint32(18).string(message.issuer); - } - if (message.issuanceDate !== "") { - writer.uint32(26).string(message.issuanceDate); - } - if (message.expirationDate !== "") { - writer.uint32(34).string(message.expirationDate); - } - if (message.credentialHash !== "") { - writer.uint32(42).string(message.credentialHash); - } - if (message.proof !== undefined) { - CredentialProof.encode(message.proof, writer.uint32(50).fork()).ldelim(); - } - return writer; - }, - - decode(input: Reader | Uint8Array, length?: number): Credential { - const reader = input instanceof Uint8Array ? new Reader(input) : input; - let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseCredential } as Credential; - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.claim = Claim.decode(reader, reader.uint32()); - break; - case 2: - message.issuer = reader.string(); - break; - case 3: - message.issuanceDate = reader.string(); - break; - case 4: - message.expirationDate = reader.string(); - break; - case 5: - message.credentialHash = reader.string(); - break; - case 6: - message.proof = CredentialProof.decode(reader, reader.uint32()); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): Credential { - const message = { ...baseCredential } as Credential; - if (object.claim !== undefined && object.claim !== null) { - message.claim = Claim.fromJSON(object.claim); - } else { - message.claim = undefined; - } - if (object.issuer !== undefined && object.issuer !== null) { - message.issuer = String(object.issuer); - } else { - message.issuer = ""; - } - if (object.issuanceDate !== undefined && object.issuanceDate !== null) { - message.issuanceDate = String(object.issuanceDate); - } else { - message.issuanceDate = ""; - } - if (object.expirationDate !== undefined && object.expirationDate !== null) { - message.expirationDate = String(object.expirationDate); - } else { - message.expirationDate = ""; - } - if (object.credentialHash !== undefined && object.credentialHash !== null) { - message.credentialHash = String(object.credentialHash); - } else { - message.credentialHash = ""; - } - if (object.proof !== undefined && object.proof !== null) { - message.proof = CredentialProof.fromJSON(object.proof); - } else { - message.proof = undefined; - } - return message; - }, - - toJSON(message: Credential): unknown { - const obj: any = {}; - message.claim !== undefined && - (obj.claim = message.claim ? Claim.toJSON(message.claim) : undefined); - message.issuer !== undefined && (obj.issuer = message.issuer); - message.issuanceDate !== undefined && - (obj.issuanceDate = message.issuanceDate); - message.expirationDate !== undefined && - (obj.expirationDate = message.expirationDate); - message.credentialHash !== undefined && - (obj.credentialHash = message.credentialHash); - message.proof !== undefined && - (obj.proof = message.proof - ? CredentialProof.toJSON(message.proof) - : undefined); - return obj; - }, - - fromPartial(object: DeepPartial): Credential { - const message = { ...baseCredential } as Credential; - if (object.claim !== undefined && object.claim !== null) { - message.claim = Claim.fromPartial(object.claim); - } else { - message.claim = undefined; - } - if (object.issuer !== undefined && object.issuer !== null) { - message.issuer = object.issuer; - } else { - message.issuer = ""; - } - if (object.issuanceDate !== undefined && object.issuanceDate !== null) { - message.issuanceDate = object.issuanceDate; - } else { - message.issuanceDate = ""; - } - if (object.expirationDate !== undefined && object.expirationDate !== null) { - message.expirationDate = object.expirationDate; - } else { - message.expirationDate = ""; - } - if (object.credentialHash !== undefined && object.credentialHash !== null) { - message.credentialHash = object.credentialHash; - } else { - message.credentialHash = ""; - } - if (object.proof !== undefined && object.proof !== null) { - message.proof = CredentialProof.fromPartial(object.proof); - } else { - message.proof = undefined; - } - return message; - }, -}; - -type Builtin = Date | Function | Uint8Array | string | number | undefined; -export type DeepPartial = T extends Builtin - ? T - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial; diff --git a/libs/generated/ssi/credential_schema.ts b/libs/generated/ssi/credential_schema.ts new file mode 100644 index 0000000..bedb044 --- /dev/null +++ b/libs/generated/ssi/credential_schema.ts @@ -0,0 +1,423 @@ +/* eslint-disable */ +import _m0 from "protobufjs/minimal"; +import { DocumentProof } from "./proof"; + +export const protobufPackage = "hypersign.ssi.v1"; + +export interface CredentialSchemaDocument { + type?: string | undefined; + modelVersion?: string | undefined; + id?: string | undefined; + name?: string | undefined; + author?: string | undefined; + authored?: string | undefined; + schema?: CredentialSchemaProperty | undefined; +} + +export interface CredentialSchemaProperty { + schema?: string | undefined; + description?: string | undefined; + type?: string | undefined; + properties?: string | undefined; + required?: string[] | undefined; + additionalProperties?: boolean | undefined; +} + +export interface CredentialSchemaState { + credentialSchemaDocument?: CredentialSchemaDocument | undefined; + credentialSchemaProof?: DocumentProof | undefined; +} + +function createBaseCredentialSchemaDocument(): CredentialSchemaDocument { + return {}; +} + +export const CredentialSchemaDocument = { + encode(message: CredentialSchemaDocument, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.type !== undefined && message.type !== "") { + writer.uint32(10).string(message.type); + } + if (message.modelVersion !== undefined && message.modelVersion !== "") { + writer.uint32(18).string(message.modelVersion); + } + if (message.id !== undefined && message.id !== "") { + writer.uint32(26).string(message.id); + } + if (message.name !== undefined && message.name !== "") { + writer.uint32(34).string(message.name); + } + if (message.author !== undefined && message.author !== "") { + writer.uint32(42).string(message.author); + } + if (message.authored !== undefined && message.authored !== "") { + writer.uint32(50).string(message.authored); + } + if (message.schema !== undefined) { + CredentialSchemaProperty.encode(message.schema, writer.uint32(58).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): CredentialSchemaDocument { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseCredentialSchemaDocument(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.type = reader.string(); + continue; + case 2: + if (tag !== 18) { + break; + } + + message.modelVersion = reader.string(); + continue; + case 3: + if (tag !== 26) { + break; + } + + message.id = reader.string(); + continue; + case 4: + if (tag !== 34) { + break; + } + + message.name = reader.string(); + continue; + case 5: + if (tag !== 42) { + break; + } + + message.author = reader.string(); + continue; + case 6: + if (tag !== 50) { + break; + } + + message.authored = reader.string(); + continue; + case 7: + if (tag !== 58) { + break; + } + + message.schema = CredentialSchemaProperty.decode(reader, reader.uint32()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): CredentialSchemaDocument { + return { + type: isSet(object.type) ? globalThis.String(object.type) : undefined, + modelVersion: isSet(object.modelVersion) ? globalThis.String(object.modelVersion) : undefined, + id: isSet(object.id) ? globalThis.String(object.id) : undefined, + name: isSet(object.name) ? globalThis.String(object.name) : undefined, + author: isSet(object.author) ? globalThis.String(object.author) : undefined, + authored: isSet(object.authored) ? globalThis.String(object.authored) : undefined, + schema: isSet(object.schema) ? CredentialSchemaProperty.fromJSON(object.schema) : undefined, + }; + }, + + toJSON(message: CredentialSchemaDocument): unknown { + const obj: any = {}; + if (message.type !== undefined && message.type !== "") { + obj.type = message.type; + } + if (message.modelVersion !== undefined && message.modelVersion !== "") { + obj.modelVersion = message.modelVersion; + } + if (message.id !== undefined && message.id !== "") { + obj.id = message.id; + } + if (message.name !== undefined && message.name !== "") { + obj.name = message.name; + } + if (message.author !== undefined && message.author !== "") { + obj.author = message.author; + } + if (message.authored !== undefined && message.authored !== "") { + obj.authored = message.authored; + } + if (message.schema !== undefined) { + obj.schema = CredentialSchemaProperty.toJSON(message.schema); + } + return obj; + }, + + create, I>>(base?: I): CredentialSchemaDocument { + return CredentialSchemaDocument.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): CredentialSchemaDocument { + const message = createBaseCredentialSchemaDocument(); + message.type = object.type ?? undefined; + message.modelVersion = object.modelVersion ?? undefined; + message.id = object.id ?? undefined; + message.name = object.name ?? undefined; + message.author = object.author ?? undefined; + message.authored = object.authored ?? undefined; + message.schema = (object.schema !== undefined && object.schema !== null) + ? CredentialSchemaProperty.fromPartial(object.schema) + : undefined; + return message; + }, +}; + +function createBaseCredentialSchemaProperty(): CredentialSchemaProperty { + return {}; +} + +export const CredentialSchemaProperty = { + encode(message: CredentialSchemaProperty, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.schema !== undefined && message.schema !== "") { + writer.uint32(10).string(message.schema); + } + if (message.description !== undefined && message.description !== "") { + writer.uint32(18).string(message.description); + } + if (message.type !== undefined && message.type !== "") { + writer.uint32(26).string(message.type); + } + if (message.properties !== undefined && message.properties !== "") { + writer.uint32(34).string(message.properties); + } + if (message.required !== undefined && message.required.length !== 0) { + for (const v of message.required) { + writer.uint32(42).string(v!); + } + } + if (message.additionalProperties === true) { + writer.uint32(48).bool(message.additionalProperties); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): CredentialSchemaProperty { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseCredentialSchemaProperty(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.schema = reader.string(); + continue; + case 2: + if (tag !== 18) { + break; + } + + message.description = reader.string(); + continue; + case 3: + if (tag !== 26) { + break; + } + + message.type = reader.string(); + continue; + case 4: + if (tag !== 34) { + break; + } + + message.properties = reader.string(); + continue; + case 5: + if (tag !== 42) { + break; + } + + if (message.required === undefined) { + message.required = []; + } + message.required!.push(reader.string()); + continue; + case 6: + if (tag !== 48) { + break; + } + + message.additionalProperties = reader.bool(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): CredentialSchemaProperty { + return { + schema: isSet(object.schema) ? globalThis.String(object.schema) : undefined, + description: isSet(object.description) ? globalThis.String(object.description) : undefined, + type: isSet(object.type) ? globalThis.String(object.type) : undefined, + properties: isSet(object.properties) ? globalThis.String(object.properties) : undefined, + required: globalThis.Array.isArray(object?.required) + ? object.required.map((e: any) => globalThis.String(e)) + : undefined, + additionalProperties: isSet(object.additionalProperties) + ? globalThis.Boolean(object.additionalProperties) + : undefined, + }; + }, + + toJSON(message: CredentialSchemaProperty): unknown { + const obj: any = {}; + if (message.schema !== undefined && message.schema !== "") { + obj.schema = message.schema; + } + if (message.description !== undefined && message.description !== "") { + obj.description = message.description; + } + if (message.type !== undefined && message.type !== "") { + obj.type = message.type; + } + if (message.properties !== undefined && message.properties !== "") { + obj.properties = message.properties; + } + if (message.required?.length) { + obj.required = message.required; + } + if (message.additionalProperties === true) { + obj.additionalProperties = message.additionalProperties; + } + return obj; + }, + + create, I>>(base?: I): CredentialSchemaProperty { + return CredentialSchemaProperty.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): CredentialSchemaProperty { + const message = createBaseCredentialSchemaProperty(); + message.schema = object.schema ?? undefined; + message.description = object.description ?? undefined; + message.type = object.type ?? undefined; + message.properties = object.properties ?? undefined; + message.required = object.required?.map((e) => e) || undefined; + message.additionalProperties = object.additionalProperties ?? undefined; + return message; + }, +}; + +function createBaseCredentialSchemaState(): CredentialSchemaState { + return {}; +} + +export const CredentialSchemaState = { + encode(message: CredentialSchemaState, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.credentialSchemaDocument !== undefined) { + CredentialSchemaDocument.encode(message.credentialSchemaDocument, writer.uint32(10).fork()).ldelim(); + } + if (message.credentialSchemaProof !== undefined) { + DocumentProof.encode(message.credentialSchemaProof, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): CredentialSchemaState { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseCredentialSchemaState(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.credentialSchemaDocument = CredentialSchemaDocument.decode(reader, reader.uint32()); + continue; + case 2: + if (tag !== 18) { + break; + } + + message.credentialSchemaProof = DocumentProof.decode(reader, reader.uint32()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): CredentialSchemaState { + return { + credentialSchemaDocument: isSet(object.credentialSchemaDocument) + ? CredentialSchemaDocument.fromJSON(object.credentialSchemaDocument) + : undefined, + credentialSchemaProof: isSet(object.credentialSchemaProof) + ? DocumentProof.fromJSON(object.credentialSchemaProof) + : undefined, + }; + }, + + toJSON(message: CredentialSchemaState): unknown { + const obj: any = {}; + if (message.credentialSchemaDocument !== undefined) { + obj.credentialSchemaDocument = CredentialSchemaDocument.toJSON(message.credentialSchemaDocument); + } + if (message.credentialSchemaProof !== undefined) { + obj.credentialSchemaProof = DocumentProof.toJSON(message.credentialSchemaProof); + } + return obj; + }, + + create, I>>(base?: I): CredentialSchemaState { + return CredentialSchemaState.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): CredentialSchemaState { + const message = createBaseCredentialSchemaState(); + message.credentialSchemaDocument = + (object.credentialSchemaDocument !== undefined && object.credentialSchemaDocument !== null) + ? CredentialSchemaDocument.fromPartial(object.credentialSchemaDocument) + : undefined; + message.credentialSchemaProof = + (object.credentialSchemaProof !== undefined && object.credentialSchemaProof !== null) + ? DocumentProof.fromPartial(object.credentialSchemaProof) + : undefined; + return message; + }, +}; + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends globalThis.Array ? globalThis.Array> + : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/libs/generated/ssi/credential_status.ts b/libs/generated/ssi/credential_status.ts new file mode 100644 index 0000000..d47a584 --- /dev/null +++ b/libs/generated/ssi/credential_status.ts @@ -0,0 +1,271 @@ +/* eslint-disable */ +import _m0 from "protobufjs/minimal"; +import { DocumentProof } from "./proof"; + +export const protobufPackage = "hypersign.ssi.v1"; + +export interface CredentialStatusDocument { + id?: string | undefined; + revoked?: boolean | undefined; + suspended?: boolean | undefined; + remarks?: string | undefined; + issuer?: string | undefined; + issuanceDate?: string | undefined; + credentialMerkleRootHash?: string | undefined; +} + +export interface CredentialStatusState { + credentialStatusDocument?: CredentialStatusDocument | undefined; + credentialStatusProof?: DocumentProof | undefined; +} + +function createBaseCredentialStatusDocument(): CredentialStatusDocument { + return {}; +} + +export const CredentialStatusDocument = { + encode(message: CredentialStatusDocument, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.id !== undefined && message.id !== "") { + writer.uint32(10).string(message.id); + } + if (message.revoked === true) { + writer.uint32(16).bool(message.revoked); + } + if (message.suspended === true) { + writer.uint32(24).bool(message.suspended); + } + if (message.remarks !== undefined && message.remarks !== "") { + writer.uint32(34).string(message.remarks); + } + if (message.issuer !== undefined && message.issuer !== "") { + writer.uint32(42).string(message.issuer); + } + if (message.issuanceDate !== undefined && message.issuanceDate !== "") { + writer.uint32(50).string(message.issuanceDate); + } + if (message.credentialMerkleRootHash !== undefined && message.credentialMerkleRootHash !== "") { + writer.uint32(58).string(message.credentialMerkleRootHash); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): CredentialStatusDocument { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseCredentialStatusDocument(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.id = reader.string(); + continue; + case 2: + if (tag !== 16) { + break; + } + + message.revoked = reader.bool(); + continue; + case 3: + if (tag !== 24) { + break; + } + + message.suspended = reader.bool(); + continue; + case 4: + if (tag !== 34) { + break; + } + + message.remarks = reader.string(); + continue; + case 5: + if (tag !== 42) { + break; + } + + message.issuer = reader.string(); + continue; + case 6: + if (tag !== 50) { + break; + } + + message.issuanceDate = reader.string(); + continue; + case 7: + if (tag !== 58) { + break; + } + + message.credentialMerkleRootHash = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): CredentialStatusDocument { + return { + id: isSet(object.id) ? globalThis.String(object.id) : undefined, + revoked: isSet(object.revoked) ? globalThis.Boolean(object.revoked) : undefined, + suspended: isSet(object.suspended) ? globalThis.Boolean(object.suspended) : undefined, + remarks: isSet(object.remarks) ? globalThis.String(object.remarks) : undefined, + issuer: isSet(object.issuer) ? globalThis.String(object.issuer) : undefined, + issuanceDate: isSet(object.issuanceDate) ? globalThis.String(object.issuanceDate) : undefined, + credentialMerkleRootHash: isSet(object.credentialMerkleRootHash) + ? globalThis.String(object.credentialMerkleRootHash) + : undefined, + }; + }, + + toJSON(message: CredentialStatusDocument): unknown { + const obj: any = {}; + if (message.id !== undefined && message.id !== "") { + obj.id = message.id; + } + if (message.revoked === true) { + obj.revoked = message.revoked; + } + if (message.suspended === true) { + obj.suspended = message.suspended; + } + if (message.remarks !== undefined && message.remarks !== "") { + obj.remarks = message.remarks; + } + if (message.issuer !== undefined && message.issuer !== "") { + obj.issuer = message.issuer; + } + if (message.issuanceDate !== undefined && message.issuanceDate !== "") { + obj.issuanceDate = message.issuanceDate; + } + if (message.credentialMerkleRootHash !== undefined && message.credentialMerkleRootHash !== "") { + obj.credentialMerkleRootHash = message.credentialMerkleRootHash; + } + return obj; + }, + + create, I>>(base?: I): CredentialStatusDocument { + return CredentialStatusDocument.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): CredentialStatusDocument { + const message = createBaseCredentialStatusDocument(); + message.id = object.id ?? undefined; + message.revoked = object.revoked ?? undefined; + message.suspended = object.suspended ?? undefined; + message.remarks = object.remarks ?? undefined; + message.issuer = object.issuer ?? undefined; + message.issuanceDate = object.issuanceDate ?? undefined; + message.credentialMerkleRootHash = object.credentialMerkleRootHash ?? undefined; + return message; + }, +}; + +function createBaseCredentialStatusState(): CredentialStatusState { + return {}; +} + +export const CredentialStatusState = { + encode(message: CredentialStatusState, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.credentialStatusDocument !== undefined) { + CredentialStatusDocument.encode(message.credentialStatusDocument, writer.uint32(10).fork()).ldelim(); + } + if (message.credentialStatusProof !== undefined) { + DocumentProof.encode(message.credentialStatusProof, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): CredentialStatusState { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseCredentialStatusState(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.credentialStatusDocument = CredentialStatusDocument.decode(reader, reader.uint32()); + continue; + case 2: + if (tag !== 18) { + break; + } + + message.credentialStatusProof = DocumentProof.decode(reader, reader.uint32()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): CredentialStatusState { + return { + credentialStatusDocument: isSet(object.credentialStatusDocument) + ? CredentialStatusDocument.fromJSON(object.credentialStatusDocument) + : undefined, + credentialStatusProof: isSet(object.credentialStatusProof) + ? DocumentProof.fromJSON(object.credentialStatusProof) + : undefined, + }; + }, + + toJSON(message: CredentialStatusState): unknown { + const obj: any = {}; + if (message.credentialStatusDocument !== undefined) { + obj.credentialStatusDocument = CredentialStatusDocument.toJSON(message.credentialStatusDocument); + } + if (message.credentialStatusProof !== undefined) { + obj.credentialStatusProof = DocumentProof.toJSON(message.credentialStatusProof); + } + return obj; + }, + + create, I>>(base?: I): CredentialStatusState { + return CredentialStatusState.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): CredentialStatusState { + const message = createBaseCredentialStatusState(); + message.credentialStatusDocument = + (object.credentialStatusDocument !== undefined && object.credentialStatusDocument !== null) + ? CredentialStatusDocument.fromPartial(object.credentialStatusDocument) + : undefined; + message.credentialStatusProof = + (object.credentialStatusProof !== undefined && object.credentialStatusProof !== null) + ? DocumentProof.fromPartial(object.credentialStatusProof) + : undefined; + return message; + }, +}; + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends globalThis.Array ? globalThis.Array> + : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/libs/generated/ssi/did.ts b/libs/generated/ssi/did.ts index 351d582..c817258 100644 --- a/libs/generated/ssi/did.ts +++ b/libs/generated/ssi/did.ts @@ -1,946 +1,739 @@ /* eslint-disable */ -import { ClientSpec } from "./clientSpec"; -import { Writer, Reader } from "protobufjs/minimal"; - -export const protobufPackage = "hypersignprotocol.hidnode.ssi"; - -export interface Did { - context: string[]; - id: string; - controller: string[]; - alsoKnownAs: string[]; - verificationMethod: VerificationMethod[]; - authentication: string[]; - assertionMethod: string[]; - keyAgreement: string[]; - capabilityInvocation: string[]; - capabilityDelegation: string[]; - service: Service[]; +import _m0 from "protobufjs/minimal"; + +export const protobufPackage = "hypersign.ssi.v1"; + +export interface DidDocument { + "@context"?: string[] | undefined; + id?: string | undefined; + controller?: string[] | undefined; + alsoKnownAs?: string[] | undefined; + verificationMethod?: VerificationMethod[] | undefined; + authentication?: string[] | undefined; + assertionMethod?: string[] | undefined; + keyAgreement?: string[] | undefined; + capabilityInvocation?: string[] | undefined; + capabilityDelegation?: string[] | undefined; + service?: Service[] | undefined; } -export interface Metadata { - created: string; - updated: string; - deactivated: boolean; - versionId: string; +export interface DidDocumentMetadata { + created?: string | undefined; + updated?: string | undefined; + deactivated?: boolean | undefined; + versionId?: string | undefined; } export interface VerificationMethod { - id: string; - type: string; - controller: string; + id?: string | undefined; + type?: string | undefined; + controller?: + | string + | undefined; /** If value is provided, `blockchainAccountId` must be empty */ - publicKeyMultibase: string; + publicKeyMultibase?: + | string + | undefined; /** If value is provided, `publicKeyMultibase` must be empty */ - blockchainAccountId: string; + blockchainAccountId?: string | undefined; } export interface Service { - id: string; - type: string; - serviceEndpoint: string; -} - -export interface SignInfo { - verification_method_id: string; - signature: string; - clientSpec: ClientSpec | undefined; + id?: string | undefined; + type?: string | undefined; + serviceEndpoint?: string | undefined; } export interface DidDocumentState { - didDocument: Did | undefined; - didDocumentMetadata: Metadata | undefined; + didDocument?: DidDocument | undefined; + didDocumentMetadata?: DidDocumentMetadata | undefined; } -const baseDid: object = { - context: "", - id: "", - controller: "", - alsoKnownAs: "", - authentication: "", - assertionMethod: "", - keyAgreement: "", - capabilityInvocation: "", - capabilityDelegation: "", -}; +function createBaseDidDocument(): DidDocument { + return {}; +} -export const Did = { - encode(message: Did, writer: Writer = Writer.create()): Writer { - for (const v of message.context) { - writer.uint32(10).string(v!); +export const DidDocument = { + encode(message: DidDocument, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message["@context"] !== undefined && message["@context"].length !== 0) { + for (const v of message["@context"]) { + writer.uint32(10).string(v!); + } } - if (message.id !== "") { + if (message.id !== undefined && message.id !== "") { writer.uint32(18).string(message.id); } - for (const v of message.controller) { - writer.uint32(26).string(v!); + if (message.controller !== undefined && message.controller.length !== 0) { + for (const v of message.controller) { + writer.uint32(26).string(v!); + } } - for (const v of message.alsoKnownAs) { - writer.uint32(34).string(v!); + if (message.alsoKnownAs !== undefined && message.alsoKnownAs.length !== 0) { + for (const v of message.alsoKnownAs) { + writer.uint32(34).string(v!); + } } - for (const v of message.verificationMethod) { - VerificationMethod.encode(v!, writer.uint32(42).fork()).ldelim(); + if (message.verificationMethod !== undefined && message.verificationMethod.length !== 0) { + for (const v of message.verificationMethod) { + VerificationMethod.encode(v!, writer.uint32(42).fork()).ldelim(); + } } - for (const v of message.authentication) { - writer.uint32(50).string(v!); + if (message.authentication !== undefined && message.authentication.length !== 0) { + for (const v of message.authentication) { + writer.uint32(50).string(v!); + } } - for (const v of message.assertionMethod) { - writer.uint32(58).string(v!); + if (message.assertionMethod !== undefined && message.assertionMethod.length !== 0) { + for (const v of message.assertionMethod) { + writer.uint32(58).string(v!); + } } - for (const v of message.keyAgreement) { - writer.uint32(66).string(v!); + if (message.keyAgreement !== undefined && message.keyAgreement.length !== 0) { + for (const v of message.keyAgreement) { + writer.uint32(66).string(v!); + } } - for (const v of message.capabilityInvocation) { - writer.uint32(74).string(v!); + if (message.capabilityInvocation !== undefined && message.capabilityInvocation.length !== 0) { + for (const v of message.capabilityInvocation) { + writer.uint32(74).string(v!); + } } - for (const v of message.capabilityDelegation) { - writer.uint32(82).string(v!); + if (message.capabilityDelegation !== undefined && message.capabilityDelegation.length !== 0) { + for (const v of message.capabilityDelegation) { + writer.uint32(82).string(v!); + } } - for (const v of message.service) { - Service.encode(v!, writer.uint32(90).fork()).ldelim(); + if (message.service !== undefined && message.service.length !== 0) { + for (const v of message.service) { + Service.encode(v!, writer.uint32(90).fork()).ldelim(); + } } return writer; }, - decode(input: Reader | Uint8Array, length?: number): Did { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): DidDocument { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDid } as Did; - message.context = []; - message.controller = []; - message.alsoKnownAs = []; - message.verificationMethod = []; - message.authentication = []; - message.assertionMethod = []; - message.keyAgreement = []; - message.capabilityInvocation = []; - message.capabilityDelegation = []; - message.service = []; + const message = createBaseDidDocument(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.context.push(reader.string()); - break; + if (tag !== 10) { + break; + } + + if (message["@context"] === undefined) { + message["@context"] = []; + } + message["@context"]!.push(reader.string()); + continue; case 2: + if (tag !== 18) { + break; + } + message.id = reader.string(); - break; + continue; case 3: - message.controller.push(reader.string()); - break; + if (tag !== 26) { + break; + } + + if (message.controller === undefined) { + message.controller = []; + } + message.controller!.push(reader.string()); + continue; case 4: - message.alsoKnownAs.push(reader.string()); - break; + if (tag !== 34) { + break; + } + + if (message.alsoKnownAs === undefined) { + message.alsoKnownAs = []; + } + message.alsoKnownAs!.push(reader.string()); + continue; case 5: - message.verificationMethod.push( - VerificationMethod.decode(reader, reader.uint32()) - ); - break; + if (tag !== 42) { + break; + } + + if (message.verificationMethod === undefined) { + message.verificationMethod = []; + } + message.verificationMethod!.push(VerificationMethod.decode(reader, reader.uint32())); + continue; case 6: - message.authentication.push(reader.string()); - break; + if (tag !== 50) { + break; + } + + if (message.authentication === undefined) { + message.authentication = []; + } + message.authentication!.push(reader.string()); + continue; case 7: - message.assertionMethod.push(reader.string()); - break; + if (tag !== 58) { + break; + } + + if (message.assertionMethod === undefined) { + message.assertionMethod = []; + } + message.assertionMethod!.push(reader.string()); + continue; case 8: - message.keyAgreement.push(reader.string()); - break; + if (tag !== 66) { + break; + } + + if (message.keyAgreement === undefined) { + message.keyAgreement = []; + } + message.keyAgreement!.push(reader.string()); + continue; case 9: - message.capabilityInvocation.push(reader.string()); - break; + if (tag !== 74) { + break; + } + + if (message.capabilityInvocation === undefined) { + message.capabilityInvocation = []; + } + message.capabilityInvocation!.push(reader.string()); + continue; case 10: - message.capabilityDelegation.push(reader.string()); - break; + if (tag !== 82) { + break; + } + + if (message.capabilityDelegation === undefined) { + message.capabilityDelegation = []; + } + message.capabilityDelegation!.push(reader.string()); + continue; case 11: - message.service.push(Service.decode(reader, reader.uint32())); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): Did { - const message = { ...baseDid } as Did; - message.context = []; - message.controller = []; - message.alsoKnownAs = []; - message.verificationMethod = []; - message.authentication = []; - message.assertionMethod = []; - message.keyAgreement = []; - message.capabilityInvocation = []; - message.capabilityDelegation = []; - message.service = []; - if (object.context !== undefined && object.context !== null) { - for (const e of object.context) { - message.context.push(String(e)); - } - } - if (object.id !== undefined && object.id !== null) { - message.id = String(object.id); - } else { - message.id = ""; - } - if (object.controller !== undefined && object.controller !== null) { - for (const e of object.controller) { - message.controller.push(String(e)); - } - } - if (object.alsoKnownAs !== undefined && object.alsoKnownAs !== null) { - for (const e of object.alsoKnownAs) { - message.alsoKnownAs.push(String(e)); - } - } - if ( - object.verificationMethod !== undefined && - object.verificationMethod !== null - ) { - for (const e of object.verificationMethod) { - message.verificationMethod.push(VerificationMethod.fromJSON(e)); - } - } - if (object.authentication !== undefined && object.authentication !== null) { - for (const e of object.authentication) { - message.authentication.push(String(e)); - } - } - if ( - object.assertionMethod !== undefined && - object.assertionMethod !== null - ) { - for (const e of object.assertionMethod) { - message.assertionMethod.push(String(e)); - } - } - if (object.keyAgreement !== undefined && object.keyAgreement !== null) { - for (const e of object.keyAgreement) { - message.keyAgreement.push(String(e)); - } - } - if ( - object.capabilityInvocation !== undefined && - object.capabilityInvocation !== null - ) { - for (const e of object.capabilityInvocation) { - message.capabilityInvocation.push(String(e)); - } - } - if ( - object.capabilityDelegation !== undefined && - object.capabilityDelegation !== null - ) { - for (const e of object.capabilityDelegation) { - message.capabilityDelegation.push(String(e)); + if (tag !== 90) { + break; + } + + if (message.service === undefined) { + message.service = []; + } + message.service!.push(Service.decode(reader, reader.uint32())); + continue; } - } - if (object.service !== undefined && object.service !== null) { - for (const e of object.service) { - message.service.push(Service.fromJSON(e)); + if ((tag & 7) === 4 || tag === 0) { + break; } + reader.skipType(tag & 7); } return message; }, - toJSON(message: Did): unknown { - const obj: any = {}; - if (message.context) { - obj.context = message.context.map((e) => e); - } else { - obj.context = []; - } - message.id !== undefined && (obj.id = message.id); - if (message.controller) { - obj.controller = message.controller.map((e) => e); - } else { - obj.controller = []; - } - if (message.alsoKnownAs) { - obj.alsoKnownAs = message.alsoKnownAs.map((e) => e); - } else { - obj.alsoKnownAs = []; - } - if (message.verificationMethod) { - obj.verificationMethod = message.verificationMethod.map((e) => - e ? VerificationMethod.toJSON(e) : undefined - ); - } else { - obj.verificationMethod = []; - } - if (message.authentication) { - obj.authentication = message.authentication.map((e) => e); - } else { - obj.authentication = []; - } - if (message.assertionMethod) { - obj.assertionMethod = message.assertionMethod.map((e) => e); - } else { - obj.assertionMethod = []; - } - if (message.keyAgreement) { - obj.keyAgreement = message.keyAgreement.map((e) => e); - } else { - obj.keyAgreement = []; - } - if (message.capabilityInvocation) { - obj.capabilityInvocation = message.capabilityInvocation.map((e) => e); - } else { - obj.capabilityInvocation = []; - } - if (message.capabilityDelegation) { - obj.capabilityDelegation = message.capabilityDelegation.map((e) => e); - } else { - obj.capabilityDelegation = []; - } - if (message.service) { - obj.service = message.service.map((e) => - e ? Service.toJSON(e) : undefined - ); - } else { - obj.service = []; - } - return obj; + fromJSON(object: any): DidDocument { + return { + "@context": globalThis.Array.isArray(object?.["@context"]) + ? object["@context"].map((e: any) => globalThis.String(e)) + : undefined, + id: isSet(object.id) ? globalThis.String(object.id) : undefined, + controller: globalThis.Array.isArray(object?.controller) + ? object.controller.map((e: any) => globalThis.String(e)) + : undefined, + alsoKnownAs: globalThis.Array.isArray(object?.alsoKnownAs) + ? object.alsoKnownAs.map((e: any) => globalThis.String(e)) + : undefined, + verificationMethod: globalThis.Array.isArray(object?.verificationMethod) + ? object.verificationMethod.map((e: any) => VerificationMethod.fromJSON(e)) + : undefined, + authentication: globalThis.Array.isArray(object?.authentication) + ? object.authentication.map((e: any) => globalThis.String(e)) + : undefined, + assertionMethod: globalThis.Array.isArray(object?.assertionMethod) + ? object.assertionMethod.map((e: any) => globalThis.String(e)) + : undefined, + keyAgreement: globalThis.Array.isArray(object?.keyAgreement) + ? object.keyAgreement.map((e: any) => globalThis.String(e)) + : undefined, + capabilityInvocation: globalThis.Array.isArray(object?.capabilityInvocation) + ? object.capabilityInvocation.map((e: any) => globalThis.String(e)) + : undefined, + capabilityDelegation: globalThis.Array.isArray(object?.capabilityDelegation) + ? object.capabilityDelegation.map((e: any) => globalThis.String(e)) + : undefined, + service: globalThis.Array.isArray(object?.service) + ? object.service.map((e: any) => Service.fromJSON(e)) + : undefined, + }; }, - fromPartial(object: DeepPartial): Did { - const message = { ...baseDid } as Did; - message.context = []; - message.controller = []; - message.alsoKnownAs = []; - message.verificationMethod = []; - message.authentication = []; - message.assertionMethod = []; - message.keyAgreement = []; - message.capabilityInvocation = []; - message.capabilityDelegation = []; - message.service = []; - if (object.context !== undefined && object.context !== null) { - for (const e of object.context) { - message.context.push(e); - } + toJSON(message: DidDocument): unknown { + const obj: any = {}; + if (message["@context"]?.length) { + obj["@context"] = message["@context"]; } - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = ""; + if (message.id !== undefined && message.id !== "") { + obj.id = message.id; } - if (object.controller !== undefined && object.controller !== null) { - for (const e of object.controller) { - message.controller.push(e); - } + if (message.controller?.length) { + obj.controller = message.controller; } - if (object.alsoKnownAs !== undefined && object.alsoKnownAs !== null) { - for (const e of object.alsoKnownAs) { - message.alsoKnownAs.push(e); - } + if (message.alsoKnownAs?.length) { + obj.alsoKnownAs = message.alsoKnownAs; } - if ( - object.verificationMethod !== undefined && - object.verificationMethod !== null - ) { - for (const e of object.verificationMethod) { - message.verificationMethod.push(VerificationMethod.fromPartial(e)); - } + if (message.verificationMethod?.length) { + obj.verificationMethod = message.verificationMethod.map((e) => VerificationMethod.toJSON(e)); } - if (object.authentication !== undefined && object.authentication !== null) { - for (const e of object.authentication) { - message.authentication.push(e); - } + if (message.authentication?.length) { + obj.authentication = message.authentication; } - if ( - object.assertionMethod !== undefined && - object.assertionMethod !== null - ) { - for (const e of object.assertionMethod) { - message.assertionMethod.push(e); - } + if (message.assertionMethod?.length) { + obj.assertionMethod = message.assertionMethod; } - if (object.keyAgreement !== undefined && object.keyAgreement !== null) { - for (const e of object.keyAgreement) { - message.keyAgreement.push(e); - } + if (message.keyAgreement?.length) { + obj.keyAgreement = message.keyAgreement; } - if ( - object.capabilityInvocation !== undefined && - object.capabilityInvocation !== null - ) { - for (const e of object.capabilityInvocation) { - message.capabilityInvocation.push(e); - } + if (message.capabilityInvocation?.length) { + obj.capabilityInvocation = message.capabilityInvocation; } - if ( - object.capabilityDelegation !== undefined && - object.capabilityDelegation !== null - ) { - for (const e of object.capabilityDelegation) { - message.capabilityDelegation.push(e); - } + if (message.capabilityDelegation?.length) { + obj.capabilityDelegation = message.capabilityDelegation; } - if (object.service !== undefined && object.service !== null) { - for (const e of object.service) { - message.service.push(Service.fromPartial(e)); - } + if (message.service?.length) { + obj.service = message.service.map((e) => Service.toJSON(e)); } + return obj; + }, + + create, I>>(base?: I): DidDocument { + return DidDocument.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): DidDocument { + const message = createBaseDidDocument(); + message["@context"] = object["@context"]?.map((e) => e) || undefined; + message.id = object.id ?? undefined; + message.controller = object.controller?.map((e) => e) || undefined; + message.alsoKnownAs = object.alsoKnownAs?.map((e) => e) || undefined; + message.verificationMethod = object.verificationMethod?.map((e) => VerificationMethod.fromPartial(e)) || undefined; + message.authentication = object.authentication?.map((e) => e) || undefined; + message.assertionMethod = object.assertionMethod?.map((e) => e) || undefined; + message.keyAgreement = object.keyAgreement?.map((e) => e) || undefined; + message.capabilityInvocation = object.capabilityInvocation?.map((e) => e) || undefined; + message.capabilityDelegation = object.capabilityDelegation?.map((e) => e) || undefined; + message.service = object.service?.map((e) => Service.fromPartial(e)) || undefined; return message; }, }; -const baseMetadata: object = { - created: "", - updated: "", - deactivated: false, - versionId: "", -}; +function createBaseDidDocumentMetadata(): DidDocumentMetadata { + return {}; +} -export const Metadata = { - encode(message: Metadata, writer: Writer = Writer.create()): Writer { - if (message.created !== "") { +export const DidDocumentMetadata = { + encode(message: DidDocumentMetadata, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.created !== undefined && message.created !== "") { writer.uint32(10).string(message.created); } - if (message.updated !== "") { + if (message.updated !== undefined && message.updated !== "") { writer.uint32(18).string(message.updated); } if (message.deactivated === true) { writer.uint32(24).bool(message.deactivated); } - if (message.versionId !== "") { + if (message.versionId !== undefined && message.versionId !== "") { writer.uint32(34).string(message.versionId); } return writer; }, - decode(input: Reader | Uint8Array, length?: number): Metadata { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): DidDocumentMetadata { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMetadata } as Metadata; + const message = createBaseDidDocumentMetadata(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: + if (tag !== 10) { + break; + } + message.created = reader.string(); - break; + continue; case 2: + if (tag !== 18) { + break; + } + message.updated = reader.string(); - break; + continue; case 3: + if (tag !== 24) { + break; + } + message.deactivated = reader.bool(); - break; + continue; case 4: + if (tag !== 34) { + break; + } + message.versionId = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; } + reader.skipType(tag & 7); } return message; }, - fromJSON(object: any): Metadata { - const message = { ...baseMetadata } as Metadata; - if (object.created !== undefined && object.created !== null) { - message.created = String(object.created); - } else { - message.created = ""; - } - if (object.updated !== undefined && object.updated !== null) { - message.updated = String(object.updated); - } else { - message.updated = ""; - } - if (object.deactivated !== undefined && object.deactivated !== null) { - message.deactivated = Boolean(object.deactivated); - } else { - message.deactivated = false; - } - if (object.versionId !== undefined && object.versionId !== null) { - message.versionId = String(object.versionId); - } else { - message.versionId = ""; - } - return message; + fromJSON(object: any): DidDocumentMetadata { + return { + created: isSet(object.created) ? globalThis.String(object.created) : undefined, + updated: isSet(object.updated) ? globalThis.String(object.updated) : undefined, + deactivated: isSet(object.deactivated) ? globalThis.Boolean(object.deactivated) : undefined, + versionId: isSet(object.versionId) ? globalThis.String(object.versionId) : undefined, + }; }, - toJSON(message: Metadata): unknown { + toJSON(message: DidDocumentMetadata): unknown { const obj: any = {}; - message.created !== undefined && (obj.created = message.created); - message.updated !== undefined && (obj.updated = message.updated); - message.deactivated !== undefined && - (obj.deactivated = message.deactivated); - message.versionId !== undefined && (obj.versionId = message.versionId); - return obj; - }, - - fromPartial(object: DeepPartial): Metadata { - const message = { ...baseMetadata } as Metadata; - if (object.created !== undefined && object.created !== null) { - message.created = object.created; - } else { - message.created = ""; + if (message.created !== undefined && message.created !== "") { + obj.created = message.created; } - if (object.updated !== undefined && object.updated !== null) { - message.updated = object.updated; - } else { - message.updated = ""; + if (message.updated !== undefined && message.updated !== "") { + obj.updated = message.updated; } - if (object.deactivated !== undefined && object.deactivated !== null) { - message.deactivated = object.deactivated; - } else { - message.deactivated = false; + if (message.deactivated === true) { + obj.deactivated = message.deactivated; } - if (object.versionId !== undefined && object.versionId !== null) { - message.versionId = object.versionId; - } else { - message.versionId = ""; + if (message.versionId !== undefined && message.versionId !== "") { + obj.versionId = message.versionId; } + return obj; + }, + + create, I>>(base?: I): DidDocumentMetadata { + return DidDocumentMetadata.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): DidDocumentMetadata { + const message = createBaseDidDocumentMetadata(); + message.created = object.created ?? undefined; + message.updated = object.updated ?? undefined; + message.deactivated = object.deactivated ?? undefined; + message.versionId = object.versionId ?? undefined; return message; }, }; -const baseVerificationMethod: object = { - id: "", - type: "", - controller: "", - publicKeyMultibase: "", - blockchainAccountId: "", -}; +function createBaseVerificationMethod(): VerificationMethod { + return {}; +} export const VerificationMethod = { - encode( - message: VerificationMethod, - writer: Writer = Writer.create() - ): Writer { - if (message.id !== "") { + encode(message: VerificationMethod, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.id !== undefined && message.id !== "") { writer.uint32(10).string(message.id); } - if (message.type !== "") { + if (message.type !== undefined && message.type !== "") { writer.uint32(18).string(message.type); } - if (message.controller !== "") { + if (message.controller !== undefined && message.controller !== "") { writer.uint32(26).string(message.controller); } - if (message.publicKeyMultibase !== "") { + if (message.publicKeyMultibase !== undefined && message.publicKeyMultibase !== "") { writer.uint32(34).string(message.publicKeyMultibase); } - if (message.blockchainAccountId !== "") { + if (message.blockchainAccountId !== undefined && message.blockchainAccountId !== "") { writer.uint32(42).string(message.blockchainAccountId); } return writer; }, - decode(input: Reader | Uint8Array, length?: number): VerificationMethod { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): VerificationMethod { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseVerificationMethod } as VerificationMethod; + const message = createBaseVerificationMethod(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: + if (tag !== 10) { + break; + } + message.id = reader.string(); - break; + continue; case 2: + if (tag !== 18) { + break; + } + message.type = reader.string(); - break; + continue; case 3: + if (tag !== 26) { + break; + } + message.controller = reader.string(); - break; + continue; case 4: + if (tag !== 34) { + break; + } + message.publicKeyMultibase = reader.string(); - break; + continue; case 5: + if (tag !== 42) { + break; + } + message.blockchainAccountId = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; } + reader.skipType(tag & 7); } return message; }, fromJSON(object: any): VerificationMethod { - const message = { ...baseVerificationMethod } as VerificationMethod; - if (object.id !== undefined && object.id !== null) { - message.id = String(object.id); - } else { - message.id = ""; - } - if (object.type !== undefined && object.type !== null) { - message.type = String(object.type); - } else { - message.type = ""; - } - if (object.controller !== undefined && object.controller !== null) { - message.controller = String(object.controller); - } else { - message.controller = ""; - } - if ( - object.publicKeyMultibase !== undefined && - object.publicKeyMultibase !== null - ) { - message.publicKeyMultibase = String(object.publicKeyMultibase); - } else { - message.publicKeyMultibase = ""; - } - if ( - object.blockchainAccountId !== undefined && - object.blockchainAccountId !== null - ) { - message.blockchainAccountId = String(object.blockchainAccountId); - } else { - message.blockchainAccountId = ""; - } - return message; + return { + id: isSet(object.id) ? globalThis.String(object.id) : undefined, + type: isSet(object.type) ? globalThis.String(object.type) : undefined, + controller: isSet(object.controller) ? globalThis.String(object.controller) : undefined, + publicKeyMultibase: isSet(object.publicKeyMultibase) ? globalThis.String(object.publicKeyMultibase) : undefined, + blockchainAccountId: isSet(object.blockchainAccountId) + ? globalThis.String(object.blockchainAccountId) + : undefined, + }; }, toJSON(message: VerificationMethod): unknown { const obj: any = {}; - message.id !== undefined && (obj.id = message.id); - message.type !== undefined && (obj.type = message.type); - message.controller !== undefined && (obj.controller = message.controller); - message.publicKeyMultibase !== undefined && - (obj.publicKeyMultibase = message.publicKeyMultibase); - message.blockchainAccountId !== undefined && - (obj.blockchainAccountId = message.blockchainAccountId); + if (message.id !== undefined && message.id !== "") { + obj.id = message.id; + } + if (message.type !== undefined && message.type !== "") { + obj.type = message.type; + } + if (message.controller !== undefined && message.controller !== "") { + obj.controller = message.controller; + } + if (message.publicKeyMultibase !== undefined && message.publicKeyMultibase !== "") { + obj.publicKeyMultibase = message.publicKeyMultibase; + } + if (message.blockchainAccountId !== undefined && message.blockchainAccountId !== "") { + obj.blockchainAccountId = message.blockchainAccountId; + } return obj; }, - fromPartial(object: DeepPartial): VerificationMethod { - const message = { ...baseVerificationMethod } as VerificationMethod; - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = ""; - } - if (object.type !== undefined && object.type !== null) { - message.type = object.type; - } else { - message.type = ""; - } - if (object.controller !== undefined && object.controller !== null) { - message.controller = object.controller; - } else { - message.controller = ""; - } - if ( - object.publicKeyMultibase !== undefined && - object.publicKeyMultibase !== null - ) { - message.publicKeyMultibase = object.publicKeyMultibase; - } else { - message.publicKeyMultibase = ""; - } - if ( - object.blockchainAccountId !== undefined && - object.blockchainAccountId !== null - ) { - message.blockchainAccountId = object.blockchainAccountId; - } else { - message.blockchainAccountId = ""; - } + create, I>>(base?: I): VerificationMethod { + return VerificationMethod.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): VerificationMethod { + const message = createBaseVerificationMethod(); + message.id = object.id ?? undefined; + message.type = object.type ?? undefined; + message.controller = object.controller ?? undefined; + message.publicKeyMultibase = object.publicKeyMultibase ?? undefined; + message.blockchainAccountId = object.blockchainAccountId ?? undefined; return message; }, }; -const baseService: object = { id: "", type: "", serviceEndpoint: "" }; +function createBaseService(): Service { + return {}; +} export const Service = { - encode(message: Service, writer: Writer = Writer.create()): Writer { - if (message.id !== "") { + encode(message: Service, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.id !== undefined && message.id !== "") { writer.uint32(10).string(message.id); } - if (message.type !== "") { + if (message.type !== undefined && message.type !== "") { writer.uint32(18).string(message.type); } - if (message.serviceEndpoint !== "") { + if (message.serviceEndpoint !== undefined && message.serviceEndpoint !== "") { writer.uint32(26).string(message.serviceEndpoint); } return writer; }, - decode(input: Reader | Uint8Array, length?: number): Service { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): Service { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseService } as Service; + const message = createBaseService(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: + if (tag !== 10) { + break; + } + message.id = reader.string(); - break; + continue; case 2: + if (tag !== 18) { + break; + } + message.type = reader.string(); - break; + continue; case 3: + if (tag !== 26) { + break; + } + message.serviceEndpoint = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; } + reader.skipType(tag & 7); } return message; }, fromJSON(object: any): Service { - const message = { ...baseService } as Service; - if (object.id !== undefined && object.id !== null) { - message.id = String(object.id); - } else { - message.id = ""; - } - if (object.type !== undefined && object.type !== null) { - message.type = String(object.type); - } else { - message.type = ""; - } - if ( - object.serviceEndpoint !== undefined && - object.serviceEndpoint !== null - ) { - message.serviceEndpoint = String(object.serviceEndpoint); - } else { - message.serviceEndpoint = ""; - } - return message; + return { + id: isSet(object.id) ? globalThis.String(object.id) : undefined, + type: isSet(object.type) ? globalThis.String(object.type) : undefined, + serviceEndpoint: isSet(object.serviceEndpoint) ? globalThis.String(object.serviceEndpoint) : undefined, + }; }, toJSON(message: Service): unknown { const obj: any = {}; - message.id !== undefined && (obj.id = message.id); - message.type !== undefined && (obj.type = message.type); - message.serviceEndpoint !== undefined && - (obj.serviceEndpoint = message.serviceEndpoint); - return obj; - }, - - fromPartial(object: DeepPartial): Service { - const message = { ...baseService } as Service; - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = ""; - } - if (object.type !== undefined && object.type !== null) { - message.type = object.type; - } else { - message.type = ""; - } - if ( - object.serviceEndpoint !== undefined && - object.serviceEndpoint !== null - ) { - message.serviceEndpoint = object.serviceEndpoint; - } else { - message.serviceEndpoint = ""; + if (message.id !== undefined && message.id !== "") { + obj.id = message.id; } - return message; - }, -}; - -const baseSignInfo: object = { verification_method_id: "", signature: "" }; - -export const SignInfo = { - encode(message: SignInfo, writer: Writer = Writer.create()): Writer { - if (message.verification_method_id !== "") { - writer.uint32(10).string(message.verification_method_id); - } - if (message.signature !== "") { - writer.uint32(18).string(message.signature); + if (message.type !== undefined && message.type !== "") { + obj.type = message.type; } - if (message.clientSpec !== undefined) { - ClientSpec.encode(message.clientSpec, writer.uint32(26).fork()).ldelim(); + if (message.serviceEndpoint !== undefined && message.serviceEndpoint !== "") { + obj.serviceEndpoint = message.serviceEndpoint; } - return writer; - }, - - decode(input: Reader | Uint8Array, length?: number): SignInfo { - const reader = input instanceof Uint8Array ? new Reader(input) : input; - let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseSignInfo } as SignInfo; - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.verification_method_id = reader.string(); - break; - case 2: - message.signature = reader.string(); - break; - case 3: - message.clientSpec = ClientSpec.decode(reader, reader.uint32()); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): SignInfo { - const message = { ...baseSignInfo } as SignInfo; - if ( - object.verification_method_id !== undefined && - object.verification_method_id !== null - ) { - message.verification_method_id = String(object.verification_method_id); - } else { - message.verification_method_id = ""; - } - if (object.signature !== undefined && object.signature !== null) { - message.signature = String(object.signature); - } else { - message.signature = ""; - } - if (object.clientSpec !== undefined && object.clientSpec !== null) { - message.clientSpec = ClientSpec.fromJSON(object.clientSpec); - } else { - message.clientSpec = undefined; - } - return message; - }, - - toJSON(message: SignInfo): unknown { - const obj: any = {}; - message.verification_method_id !== undefined && - (obj.verification_method_id = message.verification_method_id); - message.signature !== undefined && (obj.signature = message.signature); - message.clientSpec !== undefined && - (obj.clientSpec = message.clientSpec - ? ClientSpec.toJSON(message.clientSpec) - : undefined); return obj; }, - fromPartial(object: DeepPartial): SignInfo { - const message = { ...baseSignInfo } as SignInfo; - if ( - object.verification_method_id !== undefined && - object.verification_method_id !== null - ) { - message.verification_method_id = object.verification_method_id; - } else { - message.verification_method_id = ""; - } - if (object.signature !== undefined && object.signature !== null) { - message.signature = object.signature; - } else { - message.signature = ""; - } - if (object.clientSpec !== undefined && object.clientSpec !== null) { - message.clientSpec = ClientSpec.fromPartial(object.clientSpec); - } else { - message.clientSpec = undefined; - } + create, I>>(base?: I): Service { + return Service.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): Service { + const message = createBaseService(); + message.id = object.id ?? undefined; + message.type = object.type ?? undefined; + message.serviceEndpoint = object.serviceEndpoint ?? undefined; return message; }, }; -const baseDidDocumentState: object = {}; +function createBaseDidDocumentState(): DidDocumentState { + return {}; +} export const DidDocumentState = { - encode(message: DidDocumentState, writer: Writer = Writer.create()): Writer { + encode(message: DidDocumentState, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { if (message.didDocument !== undefined) { - Did.encode(message.didDocument, writer.uint32(10).fork()).ldelim(); + DidDocument.encode(message.didDocument, writer.uint32(10).fork()).ldelim(); } if (message.didDocumentMetadata !== undefined) { - Metadata.encode( - message.didDocumentMetadata, - writer.uint32(18).fork() - ).ldelim(); + DidDocumentMetadata.encode(message.didDocumentMetadata, writer.uint32(18).fork()).ldelim(); } return writer; }, - decode(input: Reader | Uint8Array, length?: number): DidDocumentState { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): DidDocumentState { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseDidDocumentState } as DidDocumentState; + const message = createBaseDidDocumentState(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.didDocument = Did.decode(reader, reader.uint32()); - break; + if (tag !== 10) { + break; + } + + message.didDocument = DidDocument.decode(reader, reader.uint32()); + continue; case 2: - message.didDocumentMetadata = Metadata.decode( - reader, - reader.uint32() - ); - break; - default: - reader.skipType(tag & 7); - break; + if (tag !== 18) { + break; + } + + message.didDocumentMetadata = DidDocumentMetadata.decode(reader, reader.uint32()); + continue; } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); } return message; }, fromJSON(object: any): DidDocumentState { - const message = { ...baseDidDocumentState } as DidDocumentState; - if (object.didDocument !== undefined && object.didDocument !== null) { - message.didDocument = Did.fromJSON(object.didDocument); - } else { - message.didDocument = undefined; - } - if ( - object.didDocumentMetadata !== undefined && - object.didDocumentMetadata !== null - ) { - message.didDocumentMetadata = Metadata.fromJSON( - object.didDocumentMetadata - ); - } else { - message.didDocumentMetadata = undefined; - } - return message; + return { + didDocument: isSet(object.didDocument) ? DidDocument.fromJSON(object.didDocument) : undefined, + didDocumentMetadata: isSet(object.didDocumentMetadata) + ? DidDocumentMetadata.fromJSON(object.didDocumentMetadata) + : undefined, + }; }, toJSON(message: DidDocumentState): unknown { const obj: any = {}; - message.didDocument !== undefined && - (obj.didDocument = message.didDocument - ? Did.toJSON(message.didDocument) - : undefined); - message.didDocumentMetadata !== undefined && - (obj.didDocumentMetadata = message.didDocumentMetadata - ? Metadata.toJSON(message.didDocumentMetadata) - : undefined); + if (message.didDocument !== undefined) { + obj.didDocument = DidDocument.toJSON(message.didDocument); + } + if (message.didDocumentMetadata !== undefined) { + obj.didDocumentMetadata = DidDocumentMetadata.toJSON(message.didDocumentMetadata); + } return obj; }, - fromPartial(object: DeepPartial): DidDocumentState { - const message = { ...baseDidDocumentState } as DidDocumentState; - if (object.didDocument !== undefined && object.didDocument !== null) { - message.didDocument = Did.fromPartial(object.didDocument); - } else { - message.didDocument = undefined; - } - if ( - object.didDocumentMetadata !== undefined && - object.didDocumentMetadata !== null - ) { - message.didDocumentMetadata = Metadata.fromPartial( - object.didDocumentMetadata - ); - } else { - message.didDocumentMetadata = undefined; - } + create, I>>(base?: I): DidDocumentState { + return DidDocumentState.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): DidDocumentState { + const message = createBaseDidDocumentState(); + message.didDocument = (object.didDocument !== undefined && object.didDocument !== null) + ? DidDocument.fromPartial(object.didDocument) + : undefined; + message.didDocumentMetadata = (object.didDocumentMetadata !== undefined && object.didDocumentMetadata !== null) + ? DidDocumentMetadata.fromPartial(object.didDocumentMetadata) + : undefined; return message; }, }; -type Builtin = Date | Function | Uint8Array | string | number | undefined; -export type DeepPartial = T extends Builtin - ? T - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends globalThis.Array ? globalThis.Array> + : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/libs/generated/ssi/genesis.ts b/libs/generated/ssi/genesis.ts new file mode 100644 index 0000000..b3098bd --- /dev/null +++ b/libs/generated/ssi/genesis.ts @@ -0,0 +1,82 @@ +/* eslint-disable */ +import _m0 from "protobufjs/minimal"; + +export const protobufPackage = "hypersign.ssi.v1"; + +/** GenesisState defines the ssi module's genesis state. */ +export interface GenesisState { + chainNamespace?: string | undefined; +} + +function createBaseGenesisState(): GenesisState { + return {}; +} + +export const GenesisState = { + encode(message: GenesisState, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.chainNamespace !== undefined && message.chainNamespace !== "") { + writer.uint32(10).string(message.chainNamespace); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): GenesisState { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseGenesisState(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.chainNamespace = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): GenesisState { + return { chainNamespace: isSet(object.chainNamespace) ? globalThis.String(object.chainNamespace) : undefined }; + }, + + toJSON(message: GenesisState): unknown { + const obj: any = {}; + if (message.chainNamespace !== undefined && message.chainNamespace !== "") { + obj.chainNamespace = message.chainNamespace; + } + return obj; + }, + + create, I>>(base?: I): GenesisState { + return GenesisState.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): GenesisState { + const message = createBaseGenesisState(); + message.chainNamespace = object.chainNamespace ?? undefined; + return message; + }, +}; + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends globalThis.Array ? globalThis.Array> + : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/libs/generated/ssi/proof.ts b/libs/generated/ssi/proof.ts new file mode 100644 index 0000000..283a127 --- /dev/null +++ b/libs/generated/ssi/proof.ts @@ -0,0 +1,164 @@ +/* eslint-disable */ +import _m0 from "protobufjs/minimal"; +import { ClientSpecType, clientSpecTypeFromJSON, clientSpecTypeToJSON, clientSpecTypeToNumber } from "./client_spec"; + +export const protobufPackage = "hypersign.ssi.v1"; + +export interface DocumentProof { + type?: string | undefined; + created?: string | undefined; + verificationMethod?: string | undefined; + proofPurpose?: string | undefined; + proofValue?: string | undefined; + clientSpecType?: ClientSpecType | undefined; +} + +function createBaseDocumentProof(): DocumentProof { + return {}; +} + +export const DocumentProof = { + encode(message: DocumentProof, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.type !== undefined && message.type !== "") { + writer.uint32(10).string(message.type); + } + if (message.created !== undefined && message.created !== "") { + writer.uint32(18).string(message.created); + } + if (message.verificationMethod !== undefined && message.verificationMethod !== "") { + writer.uint32(26).string(message.verificationMethod); + } + if (message.proofPurpose !== undefined && message.proofPurpose !== "") { + writer.uint32(34).string(message.proofPurpose); + } + if (message.proofValue !== undefined && message.proofValue !== "") { + writer.uint32(42).string(message.proofValue); + } + if (message.clientSpecType !== undefined && message.clientSpecType !== ClientSpecType.CLIENT_SPEC_TYPE_NONE) { + writer.uint32(48).int32(clientSpecTypeToNumber(message.clientSpecType)); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): DocumentProof { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseDocumentProof(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.type = reader.string(); + continue; + case 2: + if (tag !== 18) { + break; + } + + message.created = reader.string(); + continue; + case 3: + if (tag !== 26) { + break; + } + + message.verificationMethod = reader.string(); + continue; + case 4: + if (tag !== 34) { + break; + } + + message.proofPurpose = reader.string(); + continue; + case 5: + if (tag !== 42) { + break; + } + + message.proofValue = reader.string(); + continue; + case 6: + if (tag !== 48) { + break; + } + + message.clientSpecType = clientSpecTypeFromJSON(reader.int32()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): DocumentProof { + return { + type: isSet(object.type) ? globalThis.String(object.type) : undefined, + created: isSet(object.created) ? globalThis.String(object.created) : undefined, + verificationMethod: isSet(object.verificationMethod) ? globalThis.String(object.verificationMethod) : undefined, + proofPurpose: isSet(object.proofPurpose) ? globalThis.String(object.proofPurpose) : undefined, + proofValue: isSet(object.proofValue) ? globalThis.String(object.proofValue) : undefined, + clientSpecType: isSet(object.clientSpecType) ? clientSpecTypeFromJSON(object.clientSpecType) : undefined, + }; + }, + + toJSON(message: DocumentProof): unknown { + const obj: any = {}; + if (message.type !== undefined && message.type !== "") { + obj.type = message.type; + } + if (message.created !== undefined && message.created !== "") { + obj.created = message.created; + } + if (message.verificationMethod !== undefined && message.verificationMethod !== "") { + obj.verificationMethod = message.verificationMethod; + } + if (message.proofPurpose !== undefined && message.proofPurpose !== "") { + obj.proofPurpose = message.proofPurpose; + } + if (message.proofValue !== undefined && message.proofValue !== "") { + obj.proofValue = message.proofValue; + } + if (message.clientSpecType !== undefined && message.clientSpecType !== ClientSpecType.CLIENT_SPEC_TYPE_NONE) { + obj.clientSpecType = clientSpecTypeToJSON(message.clientSpecType); + } + return obj; + }, + + create, I>>(base?: I): DocumentProof { + return DocumentProof.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): DocumentProof { + const message = createBaseDocumentProof(); + message.type = object.type ?? undefined; + message.created = object.created ?? undefined; + message.verificationMethod = object.verificationMethod ?? undefined; + message.proofPurpose = object.proofPurpose ?? undefined; + message.proofValue = object.proofValue ?? undefined; + message.clientSpecType = object.clientSpecType ?? undefined; + return message; + }, +}; + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends globalThis.Array ? globalThis.Array> + : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/libs/generated/ssi/schema.ts b/libs/generated/ssi/schema.ts deleted file mode 100644 index a8f7ea0..0000000 --- a/libs/generated/ssi/schema.ts +++ /dev/null @@ -1,708 +0,0 @@ -/* eslint-disable */ -import { Writer, Reader } from "protobufjs/minimal"; - -export const protobufPackage = "hypersignprotocol.hidnode.ssi"; - -export interface SchemaDocument { - type: string; - modelVersion: string; - id: string; - name: string; - author: string; - authored: string; - schema: SchemaProperty | undefined; -} - -export interface SchemaProperty { - schema: string; - description: string; - type: string; - properties: string; - required: string[]; - additionalProperties: boolean; -} - -export interface SchemaProof { - type: string; - created: string; - verificationMethod: string; - proofPurpose: string; - proofValue: string; -} - -export interface Schema { - type: string; - modelVersion: string; - id: string; - name: string; - author: string; - authored: string; - schema: SchemaProperty | undefined; - proof: SchemaProof | undefined; -} - -const baseSchemaDocument: object = { - type: "", - modelVersion: "", - id: "", - name: "", - author: "", - authored: "", -}; - -export const SchemaDocument = { - encode(message: SchemaDocument, writer: Writer = Writer.create()): Writer { - if (message.type !== "") { - writer.uint32(10).string(message.type); - } - if (message.modelVersion !== "") { - writer.uint32(18).string(message.modelVersion); - } - if (message.id !== "") { - writer.uint32(26).string(message.id); - } - if (message.name !== "") { - writer.uint32(34).string(message.name); - } - if (message.author !== "") { - writer.uint32(42).string(message.author); - } - if (message.authored !== "") { - writer.uint32(50).string(message.authored); - } - if (message.schema !== undefined) { - SchemaProperty.encode(message.schema, writer.uint32(58).fork()).ldelim(); - } - return writer; - }, - - decode(input: Reader | Uint8Array, length?: number): SchemaDocument { - const reader = input instanceof Uint8Array ? new Reader(input) : input; - let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseSchemaDocument } as SchemaDocument; - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.type = reader.string(); - break; - case 2: - message.modelVersion = reader.string(); - break; - case 3: - message.id = reader.string(); - break; - case 4: - message.name = reader.string(); - break; - case 5: - message.author = reader.string(); - break; - case 6: - message.authored = reader.string(); - break; - case 7: - message.schema = SchemaProperty.decode(reader, reader.uint32()); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): SchemaDocument { - const message = { ...baseSchemaDocument } as SchemaDocument; - if (object.type !== undefined && object.type !== null) { - message.type = String(object.type); - } else { - message.type = ""; - } - if (object.modelVersion !== undefined && object.modelVersion !== null) { - message.modelVersion = String(object.modelVersion); - } else { - message.modelVersion = ""; - } - if (object.id !== undefined && object.id !== null) { - message.id = String(object.id); - } else { - message.id = ""; - } - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.author !== undefined && object.author !== null) { - message.author = String(object.author); - } else { - message.author = ""; - } - if (object.authored !== undefined && object.authored !== null) { - message.authored = String(object.authored); - } else { - message.authored = ""; - } - if (object.schema !== undefined && object.schema !== null) { - message.schema = SchemaProperty.fromJSON(object.schema); - } else { - message.schema = undefined; - } - return message; - }, - - toJSON(message: SchemaDocument): unknown { - const obj: any = {}; - message.type !== undefined && (obj.type = message.type); - message.modelVersion !== undefined && - (obj.modelVersion = message.modelVersion); - message.id !== undefined && (obj.id = message.id); - message.name !== undefined && (obj.name = message.name); - message.author !== undefined && (obj.author = message.author); - message.authored !== undefined && (obj.authored = message.authored); - message.schema !== undefined && - (obj.schema = message.schema - ? SchemaProperty.toJSON(message.schema) - : undefined); - return obj; - }, - - fromPartial(object: DeepPartial): SchemaDocument { - const message = { ...baseSchemaDocument } as SchemaDocument; - if (object.type !== undefined && object.type !== null) { - message.type = object.type; - } else { - message.type = ""; - } - if (object.modelVersion !== undefined && object.modelVersion !== null) { - message.modelVersion = object.modelVersion; - } else { - message.modelVersion = ""; - } - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = ""; - } - if (object.name !== undefined && object.name !== null) { - message.name = object.name; - } else { - message.name = ""; - } - if (object.author !== undefined && object.author !== null) { - message.author = object.author; - } else { - message.author = ""; - } - if (object.authored !== undefined && object.authored !== null) { - message.authored = object.authored; - } else { - message.authored = ""; - } - if (object.schema !== undefined && object.schema !== null) { - message.schema = SchemaProperty.fromPartial(object.schema); - } else { - message.schema = undefined; - } - return message; - }, -}; - -const baseSchemaProperty: object = { - schema: "", - description: "", - type: "", - properties: "", - required: "", - additionalProperties: false, -}; - -export const SchemaProperty = { - encode(message: SchemaProperty, writer: Writer = Writer.create()): Writer { - if (message.schema !== "") { - writer.uint32(10).string(message.schema); - } - if (message.description !== "") { - writer.uint32(18).string(message.description); - } - if (message.type !== "") { - writer.uint32(26).string(message.type); - } - if (message.properties !== "") { - writer.uint32(34).string(message.properties); - } - for (const v of message.required) { - writer.uint32(42).string(v!); - } - if (message.additionalProperties === true) { - writer.uint32(48).bool(message.additionalProperties); - } - return writer; - }, - - decode(input: Reader | Uint8Array, length?: number): SchemaProperty { - const reader = input instanceof Uint8Array ? new Reader(input) : input; - let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseSchemaProperty } as SchemaProperty; - message.required = []; - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.schema = reader.string(); - break; - case 2: - message.description = reader.string(); - break; - case 3: - message.type = reader.string(); - break; - case 4: - message.properties = reader.string(); - break; - case 5: - message.required.push(reader.string()); - break; - case 6: - message.additionalProperties = reader.bool(); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): SchemaProperty { - const message = { ...baseSchemaProperty } as SchemaProperty; - message.required = []; - if (object.schema !== undefined && object.schema !== null) { - message.schema = String(object.schema); - } else { - message.schema = ""; - } - if (object.description !== undefined && object.description !== null) { - message.description = String(object.description); - } else { - message.description = ""; - } - if (object.type !== undefined && object.type !== null) { - message.type = String(object.type); - } else { - message.type = ""; - } - if (object.properties !== undefined && object.properties !== null) { - message.properties = String(object.properties); - } else { - message.properties = ""; - } - if (object.required !== undefined && object.required !== null) { - for (const e of object.required) { - message.required.push(String(e)); - } - } - if ( - object.additionalProperties !== undefined && - object.additionalProperties !== null - ) { - message.additionalProperties = Boolean(object.additionalProperties); - } else { - message.additionalProperties = false; - } - return message; - }, - - toJSON(message: SchemaProperty): unknown { - const obj: any = {}; - message.schema !== undefined && (obj.schema = message.schema); - message.description !== undefined && - (obj.description = message.description); - message.type !== undefined && (obj.type = message.type); - message.properties !== undefined && (obj.properties = message.properties); - if (message.required) { - obj.required = message.required.map((e) => e); - } else { - obj.required = []; - } - message.additionalProperties !== undefined && - (obj.additionalProperties = message.additionalProperties); - return obj; - }, - - fromPartial(object: DeepPartial): SchemaProperty { - const message = { ...baseSchemaProperty } as SchemaProperty; - message.required = []; - if (object.schema !== undefined && object.schema !== null) { - message.schema = object.schema; - } else { - message.schema = ""; - } - if (object.description !== undefined && object.description !== null) { - message.description = object.description; - } else { - message.description = ""; - } - if (object.type !== undefined && object.type !== null) { - message.type = object.type; - } else { - message.type = ""; - } - if (object.properties !== undefined && object.properties !== null) { - message.properties = object.properties; - } else { - message.properties = ""; - } - if (object.required !== undefined && object.required !== null) { - for (const e of object.required) { - message.required.push(e); - } - } - if ( - object.additionalProperties !== undefined && - object.additionalProperties !== null - ) { - message.additionalProperties = object.additionalProperties; - } else { - message.additionalProperties = false; - } - return message; - }, -}; - -const baseSchemaProof: object = { - type: "", - created: "", - verificationMethod: "", - proofPurpose: "", - proofValue: "", -}; - -export const SchemaProof = { - encode(message: SchemaProof, writer: Writer = Writer.create()): Writer { - if (message.type !== "") { - writer.uint32(10).string(message.type); - } - if (message.created !== "") { - writer.uint32(18).string(message.created); - } - if (message.verificationMethod !== "") { - writer.uint32(34).string(message.verificationMethod); - } - if (message.proofPurpose !== "") { - writer.uint32(42).string(message.proofPurpose); - } - if (message.proofValue !== "") { - writer.uint32(50).string(message.proofValue); - } - return writer; - }, - - decode(input: Reader | Uint8Array, length?: number): SchemaProof { - const reader = input instanceof Uint8Array ? new Reader(input) : input; - let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseSchemaProof } as SchemaProof; - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.type = reader.string(); - break; - case 2: - message.created = reader.string(); - break; - case 4: - message.verificationMethod = reader.string(); - break; - case 5: - message.proofPurpose = reader.string(); - break; - case 6: - message.proofValue = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): SchemaProof { - const message = { ...baseSchemaProof } as SchemaProof; - if (object.type !== undefined && object.type !== null) { - message.type = String(object.type); - } else { - message.type = ""; - } - if (object.created !== undefined && object.created !== null) { - message.created = String(object.created); - } else { - message.created = ""; - } - if ( - object.verificationMethod !== undefined && - object.verificationMethod !== null - ) { - message.verificationMethod = String(object.verificationMethod); - } else { - message.verificationMethod = ""; - } - if (object.proofPurpose !== undefined && object.proofPurpose !== null) { - message.proofPurpose = String(object.proofPurpose); - } else { - message.proofPurpose = ""; - } - if (object.proofValue !== undefined && object.proofValue !== null) { - message.proofValue = String(object.proofValue); - } else { - message.proofValue = ""; - } - return message; - }, - - toJSON(message: SchemaProof): unknown { - const obj: any = {}; - message.type !== undefined && (obj.type = message.type); - message.created !== undefined && (obj.created = message.created); - message.verificationMethod !== undefined && - (obj.verificationMethod = message.verificationMethod); - message.proofPurpose !== undefined && - (obj.proofPurpose = message.proofPurpose); - message.proofValue !== undefined && (obj.proofValue = message.proofValue); - return obj; - }, - - fromPartial(object: DeepPartial): SchemaProof { - const message = { ...baseSchemaProof } as SchemaProof; - if (object.type !== undefined && object.type !== null) { - message.type = object.type; - } else { - message.type = ""; - } - if (object.created !== undefined && object.created !== null) { - message.created = object.created; - } else { - message.created = ""; - } - if ( - object.verificationMethod !== undefined && - object.verificationMethod !== null - ) { - message.verificationMethod = object.verificationMethod; - } else { - message.verificationMethod = ""; - } - if (object.proofPurpose !== undefined && object.proofPurpose !== null) { - message.proofPurpose = object.proofPurpose; - } else { - message.proofPurpose = ""; - } - if (object.proofValue !== undefined && object.proofValue !== null) { - message.proofValue = object.proofValue; - } else { - message.proofValue = ""; - } - return message; - }, -}; - -const baseSchema: object = { - type: "", - modelVersion: "", - id: "", - name: "", - author: "", - authored: "", -}; - -export const Schema = { - encode(message: Schema, writer: Writer = Writer.create()): Writer { - if (message.type !== "") { - writer.uint32(10).string(message.type); - } - if (message.modelVersion !== "") { - writer.uint32(18).string(message.modelVersion); - } - if (message.id !== "") { - writer.uint32(26).string(message.id); - } - if (message.name !== "") { - writer.uint32(34).string(message.name); - } - if (message.author !== "") { - writer.uint32(42).string(message.author); - } - if (message.authored !== "") { - writer.uint32(50).string(message.authored); - } - if (message.schema !== undefined) { - SchemaProperty.encode(message.schema, writer.uint32(58).fork()).ldelim(); - } - if (message.proof !== undefined) { - SchemaProof.encode(message.proof, writer.uint32(66).fork()).ldelim(); - } - return writer; - }, - - decode(input: Reader | Uint8Array, length?: number): Schema { - const reader = input instanceof Uint8Array ? new Reader(input) : input; - let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseSchema } as Schema; - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.type = reader.string(); - break; - case 2: - message.modelVersion = reader.string(); - break; - case 3: - message.id = reader.string(); - break; - case 4: - message.name = reader.string(); - break; - case 5: - message.author = reader.string(); - break; - case 6: - message.authored = reader.string(); - break; - case 7: - message.schema = SchemaProperty.decode(reader, reader.uint32()); - break; - case 8: - message.proof = SchemaProof.decode(reader, reader.uint32()); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, - - fromJSON(object: any): Schema { - const message = { ...baseSchema } as Schema; - if (object.type !== undefined && object.type !== null) { - message.type = String(object.type); - } else { - message.type = ""; - } - if (object.modelVersion !== undefined && object.modelVersion !== null) { - message.modelVersion = String(object.modelVersion); - } else { - message.modelVersion = ""; - } - if (object.id !== undefined && object.id !== null) { - message.id = String(object.id); - } else { - message.id = ""; - } - if (object.name !== undefined && object.name !== null) { - message.name = String(object.name); - } else { - message.name = ""; - } - if (object.author !== undefined && object.author !== null) { - message.author = String(object.author); - } else { - message.author = ""; - } - if (object.authored !== undefined && object.authored !== null) { - message.authored = String(object.authored); - } else { - message.authored = ""; - } - if (object.schema !== undefined && object.schema !== null) { - message.schema = SchemaProperty.fromJSON(object.schema); - } else { - message.schema = undefined; - } - if (object.proof !== undefined && object.proof !== null) { - message.proof = SchemaProof.fromJSON(object.proof); - } else { - message.proof = undefined; - } - return message; - }, - - toJSON(message: Schema): unknown { - const obj: any = {}; - message.type !== undefined && (obj.type = message.type); - message.modelVersion !== undefined && - (obj.modelVersion = message.modelVersion); - message.id !== undefined && (obj.id = message.id); - message.name !== undefined && (obj.name = message.name); - message.author !== undefined && (obj.author = message.author); - message.authored !== undefined && (obj.authored = message.authored); - message.schema !== undefined && - (obj.schema = message.schema - ? SchemaProperty.toJSON(message.schema) - : undefined); - message.proof !== undefined && - (obj.proof = message.proof - ? SchemaProof.toJSON(message.proof) - : undefined); - return obj; - }, - - fromPartial(object: DeepPartial): Schema { - const message = { ...baseSchema } as Schema; - if (object.type !== undefined && object.type !== null) { - message.type = object.type; - } else { - message.type = ""; - } - if (object.modelVersion !== undefined && object.modelVersion !== null) { - message.modelVersion = object.modelVersion; - } else { - message.modelVersion = ""; - } - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = ""; - } - if (object.name !== undefined && object.name !== null) { - message.name = object.name; - } else { - message.name = ""; - } - if (object.author !== undefined && object.author !== null) { - message.author = object.author; - } else { - message.author = ""; - } - if (object.authored !== undefined && object.authored !== null) { - message.authored = object.authored; - } else { - message.authored = ""; - } - if (object.schema !== undefined && object.schema !== null) { - message.schema = SchemaProperty.fromPartial(object.schema); - } else { - message.schema = undefined; - } - if (object.proof !== undefined && object.proof !== null) { - message.proof = SchemaProof.fromPartial(object.proof); - } else { - message.proof = undefined; - } - return message; - }, -}; - -type Builtin = Date | Function | Uint8Array | string | number | undefined; -export type DeepPartial = T extends Builtin - ? T - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial; diff --git a/libs/generated/ssi/tx.ts b/libs/generated/ssi/tx.ts index 1b6436e..489186b 100644 --- a/libs/generated/ssi/tx.ts +++ b/libs/generated/ssi/tx.ts @@ -1,1103 +1,1196 @@ /* eslint-disable */ -import { Reader, util, configure, Writer } from "protobufjs/minimal"; -import * as Long from "long"; -import { Did, SignInfo } from "./did"; -import { SchemaDocument, SchemaProof } from "./schema"; -import { ClientSpec } from "./clientSpec"; -import { CredentialStatus, CredentialProof } from "./credential"; - -export const protobufPackage = "hypersignprotocol.hidnode.ssi"; - -export interface MsgCreateDID { - didDocString: Did | undefined; - signatures: SignInfo[]; - creator: string; +import _m0 from "protobufjs/minimal"; +import { CredentialSchemaDocument } from "./credential_schema"; +import { CredentialStatusDocument } from "./credential_status"; +import { DidDocument } from "./did"; +import { DocumentProof } from "./proof"; + +export const protobufPackage = "hypersign.ssi.v1"; + +export interface MsgRegisterDID { + didDocument?: DidDocument | undefined; + didDocumentProofs?: DocumentProof[] | undefined; + txAuthor?: string | undefined; } -export interface MsgCreateDIDResponse { - id: number; +export interface MsgRegisterDIDResponse { } export interface MsgUpdateDID { - didDocString: Did | undefined; - version_id: string; - signatures: SignInfo[]; - creator: string; + didDocument?: DidDocument | undefined; + didDocumentProofs?: DocumentProof[] | undefined; + versionId?: string | undefined; + txAuthor?: string | undefined; } export interface MsgUpdateDIDResponse { - updateId: string; } -export interface MsgCreateSchema { - creator: string; - schemaDoc: SchemaDocument | undefined; - schemaProof: SchemaProof | undefined; - clientSpec: ClientSpec | undefined; +export interface MsgDeactivateDID { + didDocumentId?: string | undefined; + didDocumentProofs?: DocumentProof[] | undefined; + versionId?: string | undefined; + txAuthor?: string | undefined; } -export interface MsgCreateSchemaResponse { - id: number; +export interface MsgDeactivateDIDResponse { } -export interface MsgDeactivateDID { - creator: string; - didId: string; - version_id: string; - signatures: SignInfo[]; +export interface MsgRegisterCredentialSchema { + credentialSchemaDocument?: CredentialSchemaDocument | undefined; + credentialSchemaProof?: DocumentProof | undefined; + txAuthor?: string | undefined; } -export interface MsgDeactivateDIDResponse { - id: number; +export interface MsgRegisterCredentialSchemaResponse { +} + +export interface MsgUpdateCredentialSchema { + credentialSchemaDocument?: CredentialSchemaDocument | undefined; + credentialSchemaProof?: DocumentProof | undefined; + txAuthor?: string | undefined; +} + +export interface MsgUpdateCredentialSchemaResponse { } export interface MsgRegisterCredentialStatus { - creator: string; - credentialStatus: CredentialStatus | undefined; - proof: CredentialProof | undefined; - clientSpec: ClientSpec | undefined; + credentialStatusDocument?: CredentialStatusDocument | undefined; + credentialStatusProof?: DocumentProof | undefined; + txAuthor?: string | undefined; } export interface MsgRegisterCredentialStatusResponse { - id: number; } -const baseMsgCreateDID: object = { creator: "" }; +export interface MsgUpdateCredentialStatus { + credentialStatusDocument?: CredentialStatusDocument | undefined; + credentialStatusProof?: DocumentProof | undefined; + txAuthor?: string | undefined; +} -export const MsgCreateDID = { - encode(message: MsgCreateDID, writer: Writer = Writer.create()): Writer { - if (message.didDocString !== undefined) { - Did.encode(message.didDocString, writer.uint32(10).fork()).ldelim(); +export interface MsgUpdateCredentialStatusResponse { +} + +function createBaseMsgRegisterDID(): MsgRegisterDID { + return {}; +} + +export const MsgRegisterDID = { + encode(message: MsgRegisterDID, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.didDocument !== undefined) { + DidDocument.encode(message.didDocument, writer.uint32(10).fork()).ldelim(); } - for (const v of message.signatures) { - SignInfo.encode(v!, writer.uint32(18).fork()).ldelim(); + if (message.didDocumentProofs !== undefined && message.didDocumentProofs.length !== 0) { + for (const v of message.didDocumentProofs) { + DocumentProof.encode(v!, writer.uint32(18).fork()).ldelim(); + } } - if (message.creator !== "") { - writer.uint32(26).string(message.creator); + if (message.txAuthor !== undefined && message.txAuthor !== "") { + writer.uint32(26).string(message.txAuthor); } return writer; }, - decode(input: Reader | Uint8Array, length?: number): MsgCreateDID { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRegisterDID { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMsgCreateDID } as MsgCreateDID; - message.signatures = []; + const message = createBaseMsgRegisterDID(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.didDocString = Did.decode(reader, reader.uint32()); - break; + if (tag !== 10) { + break; + } + + message.didDocument = DidDocument.decode(reader, reader.uint32()); + continue; case 2: - message.signatures.push(SignInfo.decode(reader, reader.uint32())); - break; + if (tag !== 18) { + break; + } + + if (message.didDocumentProofs === undefined) { + message.didDocumentProofs = []; + } + message.didDocumentProofs!.push(DocumentProof.decode(reader, reader.uint32())); + continue; case 3: - message.creator = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; + if (tag !== 26) { + break; + } + + message.txAuthor = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; } + reader.skipType(tag & 7); } return message; }, - fromJSON(object: any): MsgCreateDID { - const message = { ...baseMsgCreateDID } as MsgCreateDID; - message.signatures = []; - if (object.didDocString !== undefined && object.didDocString !== null) { - message.didDocString = Did.fromJSON(object.didDocString); - } else { - message.didDocString = undefined; - } - if (object.signatures !== undefined && object.signatures !== null) { - for (const e of object.signatures) { - message.signatures.push(SignInfo.fromJSON(e)); - } - } - if (object.creator !== undefined && object.creator !== null) { - message.creator = String(object.creator); - } else { - message.creator = ""; - } - return message; + fromJSON(object: any): MsgRegisterDID { + return { + didDocument: isSet(object.didDocument) ? DidDocument.fromJSON(object.didDocument) : undefined, + didDocumentProofs: globalThis.Array.isArray(object?.didDocumentProofs) + ? object.didDocumentProofs.map((e: any) => DocumentProof.fromJSON(e)) + : undefined, + txAuthor: isSet(object.txAuthor) ? globalThis.String(object.txAuthor) : undefined, + }; }, - toJSON(message: MsgCreateDID): unknown { + toJSON(message: MsgRegisterDID): unknown { const obj: any = {}; - message.didDocString !== undefined && - (obj.didDocString = message.didDocString - ? Did.toJSON(message.didDocString) - : undefined); - if (message.signatures) { - obj.signatures = message.signatures.map((e) => - e ? SignInfo.toJSON(e) : undefined - ); - } else { - obj.signatures = []; + if (message.didDocument !== undefined) { + obj.didDocument = DidDocument.toJSON(message.didDocument); + } + if (message.didDocumentProofs?.length) { + obj.didDocumentProofs = message.didDocumentProofs.map((e) => DocumentProof.toJSON(e)); + } + if (message.txAuthor !== undefined && message.txAuthor !== "") { + obj.txAuthor = message.txAuthor; } - message.creator !== undefined && (obj.creator = message.creator); return obj; }, - fromPartial(object: DeepPartial): MsgCreateDID { - const message = { ...baseMsgCreateDID } as MsgCreateDID; - message.signatures = []; - if (object.didDocString !== undefined && object.didDocString !== null) { - message.didDocString = Did.fromPartial(object.didDocString); - } else { - message.didDocString = undefined; - } - if (object.signatures !== undefined && object.signatures !== null) { - for (const e of object.signatures) { - message.signatures.push(SignInfo.fromPartial(e)); - } - } - if (object.creator !== undefined && object.creator !== null) { - message.creator = object.creator; - } else { - message.creator = ""; - } + create, I>>(base?: I): MsgRegisterDID { + return MsgRegisterDID.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): MsgRegisterDID { + const message = createBaseMsgRegisterDID(); + message.didDocument = (object.didDocument !== undefined && object.didDocument !== null) + ? DidDocument.fromPartial(object.didDocument) + : undefined; + message.didDocumentProofs = object.didDocumentProofs?.map((e) => DocumentProof.fromPartial(e)) || undefined; + message.txAuthor = object.txAuthor ?? undefined; return message; }, }; -const baseMsgCreateDIDResponse: object = { id: 0 }; +function createBaseMsgRegisterDIDResponse(): MsgRegisterDIDResponse { + return {}; +} -export const MsgCreateDIDResponse = { - encode( - message: MsgCreateDIDResponse, - writer: Writer = Writer.create() - ): Writer { - if (message.id !== 0) { - writer.uint32(8).uint64(message.id); - } +export const MsgRegisterDIDResponse = { + encode(_: MsgRegisterDIDResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { return writer; }, - decode(input: Reader | Uint8Array, length?: number): MsgCreateDIDResponse { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRegisterDIDResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMsgCreateDIDResponse } as MsgCreateDIDResponse; + const message = createBaseMsgRegisterDIDResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { - case 1: - message.id = longToNumber(reader.uint64() as Long); - break; - default: - reader.skipType(tag & 7); - break; } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); } return message; }, - fromJSON(object: any): MsgCreateDIDResponse { - const message = { ...baseMsgCreateDIDResponse } as MsgCreateDIDResponse; - if (object.id !== undefined && object.id !== null) { - message.id = Number(object.id); - } else { - message.id = 0; - } - return message; + fromJSON(_: any): MsgRegisterDIDResponse { + return {}; }, - toJSON(message: MsgCreateDIDResponse): unknown { + toJSON(_: MsgRegisterDIDResponse): unknown { const obj: any = {}; - message.id !== undefined && (obj.id = message.id); return obj; }, - fromPartial(object: DeepPartial): MsgCreateDIDResponse { - const message = { ...baseMsgCreateDIDResponse } as MsgCreateDIDResponse; - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = 0; - } + create, I>>(base?: I): MsgRegisterDIDResponse { + return MsgRegisterDIDResponse.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(_: I): MsgRegisterDIDResponse { + const message = createBaseMsgRegisterDIDResponse(); return message; }, }; -const baseMsgUpdateDID: object = { version_id: "", creator: "" }; +function createBaseMsgUpdateDID(): MsgUpdateDID { + return {}; +} export const MsgUpdateDID = { - encode(message: MsgUpdateDID, writer: Writer = Writer.create()): Writer { - if (message.didDocString !== undefined) { - Did.encode(message.didDocString, writer.uint32(10).fork()).ldelim(); + encode(message: MsgUpdateDID, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.didDocument !== undefined) { + DidDocument.encode(message.didDocument, writer.uint32(10).fork()).ldelim(); } - if (message.version_id !== "") { - writer.uint32(18).string(message.version_id); + if (message.didDocumentProofs !== undefined && message.didDocumentProofs.length !== 0) { + for (const v of message.didDocumentProofs) { + DocumentProof.encode(v!, writer.uint32(18).fork()).ldelim(); + } } - for (const v of message.signatures) { - SignInfo.encode(v!, writer.uint32(26).fork()).ldelim(); + if (message.versionId !== undefined && message.versionId !== "") { + writer.uint32(26).string(message.versionId); } - if (message.creator !== "") { - writer.uint32(34).string(message.creator); + if (message.txAuthor !== undefined && message.txAuthor !== "") { + writer.uint32(34).string(message.txAuthor); } return writer; }, - decode(input: Reader | Uint8Array, length?: number): MsgUpdateDID { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateDID { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMsgUpdateDID } as MsgUpdateDID; - message.signatures = []; + const message = createBaseMsgUpdateDID(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.didDocString = Did.decode(reader, reader.uint32()); - break; + if (tag !== 10) { + break; + } + + message.didDocument = DidDocument.decode(reader, reader.uint32()); + continue; case 2: - message.version_id = reader.string(); - break; + if (tag !== 18) { + break; + } + + if (message.didDocumentProofs === undefined) { + message.didDocumentProofs = []; + } + message.didDocumentProofs!.push(DocumentProof.decode(reader, reader.uint32())); + continue; case 3: - message.signatures.push(SignInfo.decode(reader, reader.uint32())); - break; + if (tag !== 26) { + break; + } + + message.versionId = reader.string(); + continue; case 4: - message.creator = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; + if (tag !== 34) { + break; + } + + message.txAuthor = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; } + reader.skipType(tag & 7); } return message; }, fromJSON(object: any): MsgUpdateDID { - const message = { ...baseMsgUpdateDID } as MsgUpdateDID; - message.signatures = []; - if (object.didDocString !== undefined && object.didDocString !== null) { - message.didDocString = Did.fromJSON(object.didDocString); - } else { - message.didDocString = undefined; - } - if (object.version_id !== undefined && object.version_id !== null) { - message.version_id = String(object.version_id); - } else { - message.version_id = ""; - } - if (object.signatures !== undefined && object.signatures !== null) { - for (const e of object.signatures) { - message.signatures.push(SignInfo.fromJSON(e)); - } - } - if (object.creator !== undefined && object.creator !== null) { - message.creator = String(object.creator); - } else { - message.creator = ""; - } - return message; + return { + didDocument: isSet(object.didDocument) ? DidDocument.fromJSON(object.didDocument) : undefined, + didDocumentProofs: globalThis.Array.isArray(object?.didDocumentProofs) + ? object.didDocumentProofs.map((e: any) => DocumentProof.fromJSON(e)) + : undefined, + versionId: isSet(object.versionId) ? globalThis.String(object.versionId) : undefined, + txAuthor: isSet(object.txAuthor) ? globalThis.String(object.txAuthor) : undefined, + }; }, toJSON(message: MsgUpdateDID): unknown { const obj: any = {}; - message.didDocString !== undefined && - (obj.didDocString = message.didDocString - ? Did.toJSON(message.didDocString) - : undefined); - message.version_id !== undefined && (obj.version_id = message.version_id); - if (message.signatures) { - obj.signatures = message.signatures.map((e) => - e ? SignInfo.toJSON(e) : undefined - ); - } else { - obj.signatures = []; + if (message.didDocument !== undefined) { + obj.didDocument = DidDocument.toJSON(message.didDocument); } - message.creator !== undefined && (obj.creator = message.creator); - return obj; - }, - - fromPartial(object: DeepPartial): MsgUpdateDID { - const message = { ...baseMsgUpdateDID } as MsgUpdateDID; - message.signatures = []; - if (object.didDocString !== undefined && object.didDocString !== null) { - message.didDocString = Did.fromPartial(object.didDocString); - } else { - message.didDocString = undefined; - } - if (object.version_id !== undefined && object.version_id !== null) { - message.version_id = object.version_id; - } else { - message.version_id = ""; + if (message.didDocumentProofs?.length) { + obj.didDocumentProofs = message.didDocumentProofs.map((e) => DocumentProof.toJSON(e)); } - if (object.signatures !== undefined && object.signatures !== null) { - for (const e of object.signatures) { - message.signatures.push(SignInfo.fromPartial(e)); - } + if (message.versionId !== undefined && message.versionId !== "") { + obj.versionId = message.versionId; } - if (object.creator !== undefined && object.creator !== null) { - message.creator = object.creator; - } else { - message.creator = ""; + if (message.txAuthor !== undefined && message.txAuthor !== "") { + obj.txAuthor = message.txAuthor; } + return obj; + }, + + create, I>>(base?: I): MsgUpdateDID { + return MsgUpdateDID.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): MsgUpdateDID { + const message = createBaseMsgUpdateDID(); + message.didDocument = (object.didDocument !== undefined && object.didDocument !== null) + ? DidDocument.fromPartial(object.didDocument) + : undefined; + message.didDocumentProofs = object.didDocumentProofs?.map((e) => DocumentProof.fromPartial(e)) || undefined; + message.versionId = object.versionId ?? undefined; + message.txAuthor = object.txAuthor ?? undefined; return message; }, }; -const baseMsgUpdateDIDResponse: object = { updateId: "" }; +function createBaseMsgUpdateDIDResponse(): MsgUpdateDIDResponse { + return {}; +} export const MsgUpdateDIDResponse = { - encode( - message: MsgUpdateDIDResponse, - writer: Writer = Writer.create() - ): Writer { - if (message.updateId !== "") { - writer.uint32(10).string(message.updateId); - } + encode(_: MsgUpdateDIDResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { return writer; }, - decode(input: Reader | Uint8Array, length?: number): MsgUpdateDIDResponse { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateDIDResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMsgUpdateDIDResponse } as MsgUpdateDIDResponse; + const message = createBaseMsgUpdateDIDResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { - case 1: - message.updateId = reader.string(); - break; - default: - reader.skipType(tag & 7); - break; } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); } return message; }, - fromJSON(object: any): MsgUpdateDIDResponse { - const message = { ...baseMsgUpdateDIDResponse } as MsgUpdateDIDResponse; - if (object.updateId !== undefined && object.updateId !== null) { - message.updateId = String(object.updateId); - } else { - message.updateId = ""; - } - return message; + fromJSON(_: any): MsgUpdateDIDResponse { + return {}; }, - toJSON(message: MsgUpdateDIDResponse): unknown { + toJSON(_: MsgUpdateDIDResponse): unknown { const obj: any = {}; - message.updateId !== undefined && (obj.updateId = message.updateId); return obj; }, - fromPartial(object: DeepPartial): MsgUpdateDIDResponse { - const message = { ...baseMsgUpdateDIDResponse } as MsgUpdateDIDResponse; - if (object.updateId !== undefined && object.updateId !== null) { - message.updateId = object.updateId; - } else { - message.updateId = ""; - } + create, I>>(base?: I): MsgUpdateDIDResponse { + return MsgUpdateDIDResponse.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(_: I): MsgUpdateDIDResponse { + const message = createBaseMsgUpdateDIDResponse(); return message; }, }; -const baseMsgCreateSchema: object = { creator: "" }; +function createBaseMsgDeactivateDID(): MsgDeactivateDID { + return {}; +} -export const MsgCreateSchema = { - encode(message: MsgCreateSchema, writer: Writer = Writer.create()): Writer { - if (message.creator !== "") { - writer.uint32(10).string(message.creator); +export const MsgDeactivateDID = { + encode(message: MsgDeactivateDID, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.didDocumentId !== undefined && message.didDocumentId !== "") { + writer.uint32(10).string(message.didDocumentId); } - if (message.schemaDoc !== undefined) { - SchemaDocument.encode( - message.schemaDoc, - writer.uint32(18).fork() - ).ldelim(); + if (message.didDocumentProofs !== undefined && message.didDocumentProofs.length !== 0) { + for (const v of message.didDocumentProofs) { + DocumentProof.encode(v!, writer.uint32(18).fork()).ldelim(); + } } - if (message.schemaProof !== undefined) { - SchemaProof.encode( - message.schemaProof, - writer.uint32(26).fork() - ).ldelim(); + if (message.versionId !== undefined && message.versionId !== "") { + writer.uint32(26).string(message.versionId); } - if (message.clientSpec !== undefined) { - ClientSpec.encode(message.clientSpec, writer.uint32(34).fork()).ldelim(); + if (message.txAuthor !== undefined && message.txAuthor !== "") { + writer.uint32(34).string(message.txAuthor); } return writer; }, - decode(input: Reader | Uint8Array, length?: number): MsgCreateSchema { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgDeactivateDID { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMsgCreateSchema } as MsgCreateSchema; + const message = createBaseMsgDeactivateDID(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.creator = reader.string(); - break; + if (tag !== 10) { + break; + } + + message.didDocumentId = reader.string(); + continue; case 2: - message.schemaDoc = SchemaDocument.decode(reader, reader.uint32()); - break; + if (tag !== 18) { + break; + } + + if (message.didDocumentProofs === undefined) { + message.didDocumentProofs = []; + } + message.didDocumentProofs!.push(DocumentProof.decode(reader, reader.uint32())); + continue; case 3: - message.schemaProof = SchemaProof.decode(reader, reader.uint32()); - break; + if (tag !== 26) { + break; + } + + message.versionId = reader.string(); + continue; case 4: - message.clientSpec = ClientSpec.decode(reader, reader.uint32()); - break; - default: - reader.skipType(tag & 7); - break; + if (tag !== 34) { + break; + } + + message.txAuthor = reader.string(); + continue; } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); } return message; }, - fromJSON(object: any): MsgCreateSchema { - const message = { ...baseMsgCreateSchema } as MsgCreateSchema; - if (object.creator !== undefined && object.creator !== null) { - message.creator = String(object.creator); - } else { - message.creator = ""; - } - if (object.schemaDoc !== undefined && object.schemaDoc !== null) { - message.schemaDoc = SchemaDocument.fromJSON(object.schemaDoc); - } else { - message.schemaDoc = undefined; - } - if (object.schemaProof !== undefined && object.schemaProof !== null) { - message.schemaProof = SchemaProof.fromJSON(object.schemaProof); - } else { - message.schemaProof = undefined; - } - if (object.clientSpec !== undefined && object.clientSpec !== null) { - message.clientSpec = ClientSpec.fromJSON(object.clientSpec); - } else { - message.clientSpec = undefined; - } - return message; + fromJSON(object: any): MsgDeactivateDID { + return { + didDocumentId: isSet(object.didDocumentId) ? globalThis.String(object.didDocumentId) : undefined, + didDocumentProofs: globalThis.Array.isArray(object?.didDocumentProofs) + ? object.didDocumentProofs.map((e: any) => DocumentProof.fromJSON(e)) + : undefined, + versionId: isSet(object.versionId) ? globalThis.String(object.versionId) : undefined, + txAuthor: isSet(object.txAuthor) ? globalThis.String(object.txAuthor) : undefined, + }; }, - toJSON(message: MsgCreateSchema): unknown { + toJSON(message: MsgDeactivateDID): unknown { const obj: any = {}; - message.creator !== undefined && (obj.creator = message.creator); - message.schemaDoc !== undefined && - (obj.schemaDoc = message.schemaDoc - ? SchemaDocument.toJSON(message.schemaDoc) - : undefined); - message.schemaProof !== undefined && - (obj.schemaProof = message.schemaProof - ? SchemaProof.toJSON(message.schemaProof) - : undefined); - message.clientSpec !== undefined && - (obj.clientSpec = message.clientSpec - ? ClientSpec.toJSON(message.clientSpec) - : undefined); - return obj; - }, - - fromPartial(object: DeepPartial): MsgCreateSchema { - const message = { ...baseMsgCreateSchema } as MsgCreateSchema; - if (object.creator !== undefined && object.creator !== null) { - message.creator = object.creator; - } else { - message.creator = ""; + if (message.didDocumentId !== undefined && message.didDocumentId !== "") { + obj.didDocumentId = message.didDocumentId; } - if (object.schemaDoc !== undefined && object.schemaDoc !== null) { - message.schemaDoc = SchemaDocument.fromPartial(object.schemaDoc); - } else { - message.schemaDoc = undefined; + if (message.didDocumentProofs?.length) { + obj.didDocumentProofs = message.didDocumentProofs.map((e) => DocumentProof.toJSON(e)); } - if (object.schemaProof !== undefined && object.schemaProof !== null) { - message.schemaProof = SchemaProof.fromPartial(object.schemaProof); - } else { - message.schemaProof = undefined; + if (message.versionId !== undefined && message.versionId !== "") { + obj.versionId = message.versionId; } - if (object.clientSpec !== undefined && object.clientSpec !== null) { - message.clientSpec = ClientSpec.fromPartial(object.clientSpec); - } else { - message.clientSpec = undefined; + if (message.txAuthor !== undefined && message.txAuthor !== "") { + obj.txAuthor = message.txAuthor; } + return obj; + }, + + create, I>>(base?: I): MsgDeactivateDID { + return MsgDeactivateDID.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): MsgDeactivateDID { + const message = createBaseMsgDeactivateDID(); + message.didDocumentId = object.didDocumentId ?? undefined; + message.didDocumentProofs = object.didDocumentProofs?.map((e) => DocumentProof.fromPartial(e)) || undefined; + message.versionId = object.versionId ?? undefined; + message.txAuthor = object.txAuthor ?? undefined; return message; }, }; -const baseMsgCreateSchemaResponse: object = { id: 0 }; +function createBaseMsgDeactivateDIDResponse(): MsgDeactivateDIDResponse { + return {}; +} -export const MsgCreateSchemaResponse = { - encode( - message: MsgCreateSchemaResponse, - writer: Writer = Writer.create() - ): Writer { - if (message.id !== 0) { - writer.uint32(8).uint64(message.id); - } +export const MsgDeactivateDIDResponse = { + encode(_: MsgDeactivateDIDResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { return writer; }, - decode(input: Reader | Uint8Array, length?: number): MsgCreateSchemaResponse { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgDeactivateDIDResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseMsgCreateSchemaResponse, - } as MsgCreateSchemaResponse; + const message = createBaseMsgDeactivateDIDResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { - case 1: - message.id = longToNumber(reader.uint64() as Long); - break; - default: - reader.skipType(tag & 7); - break; } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); } return message; }, - fromJSON(object: any): MsgCreateSchemaResponse { - const message = { - ...baseMsgCreateSchemaResponse, - } as MsgCreateSchemaResponse; - if (object.id !== undefined && object.id !== null) { - message.id = Number(object.id); - } else { - message.id = 0; - } - return message; + fromJSON(_: any): MsgDeactivateDIDResponse { + return {}; }, - toJSON(message: MsgCreateSchemaResponse): unknown { + toJSON(_: MsgDeactivateDIDResponse): unknown { const obj: any = {}; - message.id !== undefined && (obj.id = message.id); return obj; }, - fromPartial( - object: DeepPartial - ): MsgCreateSchemaResponse { - const message = { - ...baseMsgCreateSchemaResponse, - } as MsgCreateSchemaResponse; - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = 0; - } + create, I>>(base?: I): MsgDeactivateDIDResponse { + return MsgDeactivateDIDResponse.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(_: I): MsgDeactivateDIDResponse { + const message = createBaseMsgDeactivateDIDResponse(); return message; }, }; -const baseMsgDeactivateDID: object = { creator: "", didId: "", version_id: "" }; +function createBaseMsgRegisterCredentialSchema(): MsgRegisterCredentialSchema { + return {}; +} -export const MsgDeactivateDID = { - encode(message: MsgDeactivateDID, writer: Writer = Writer.create()): Writer { - if (message.creator !== "") { - writer.uint32(10).string(message.creator); - } - if (message.didId !== "") { - writer.uint32(18).string(message.didId); +export const MsgRegisterCredentialSchema = { + encode(message: MsgRegisterCredentialSchema, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.credentialSchemaDocument !== undefined) { + CredentialSchemaDocument.encode(message.credentialSchemaDocument, writer.uint32(10).fork()).ldelim(); } - if (message.version_id !== "") { - writer.uint32(26).string(message.version_id); + if (message.credentialSchemaProof !== undefined) { + DocumentProof.encode(message.credentialSchemaProof, writer.uint32(18).fork()).ldelim(); } - for (const v of message.signatures) { - SignInfo.encode(v!, writer.uint32(34).fork()).ldelim(); + if (message.txAuthor !== undefined && message.txAuthor !== "") { + writer.uint32(26).string(message.txAuthor); } return writer; }, - decode(input: Reader | Uint8Array, length?: number): MsgDeactivateDID { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRegisterCredentialSchema { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { ...baseMsgDeactivateDID } as MsgDeactivateDID; - message.signatures = []; + const message = createBaseMsgRegisterCredentialSchema(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.creator = reader.string(); - break; + if (tag !== 10) { + break; + } + + message.credentialSchemaDocument = CredentialSchemaDocument.decode(reader, reader.uint32()); + continue; case 2: - message.didId = reader.string(); - break; + if (tag !== 18) { + break; + } + + message.credentialSchemaProof = DocumentProof.decode(reader, reader.uint32()); + continue; case 3: - message.version_id = reader.string(); - break; - case 4: - message.signatures.push(SignInfo.decode(reader, reader.uint32())); - break; - default: - reader.skipType(tag & 7); - break; + if (tag !== 26) { + break; + } + + message.txAuthor = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; } + reader.skipType(tag & 7); } return message; }, - fromJSON(object: any): MsgDeactivateDID { - const message = { ...baseMsgDeactivateDID } as MsgDeactivateDID; - message.signatures = []; - if (object.creator !== undefined && object.creator !== null) { - message.creator = String(object.creator); - } else { - message.creator = ""; + fromJSON(object: any): MsgRegisterCredentialSchema { + return { + credentialSchemaDocument: isSet(object.credentialSchemaDocument) + ? CredentialSchemaDocument.fromJSON(object.credentialSchemaDocument) + : undefined, + credentialSchemaProof: isSet(object.credentialSchemaProof) + ? DocumentProof.fromJSON(object.credentialSchemaProof) + : undefined, + txAuthor: isSet(object.txAuthor) ? globalThis.String(object.txAuthor) : undefined, + }; + }, + + toJSON(message: MsgRegisterCredentialSchema): unknown { + const obj: any = {}; + if (message.credentialSchemaDocument !== undefined) { + obj.credentialSchemaDocument = CredentialSchemaDocument.toJSON(message.credentialSchemaDocument); } - if (object.didId !== undefined && object.didId !== null) { - message.didId = String(object.didId); - } else { - message.didId = ""; + if (message.credentialSchemaProof !== undefined) { + obj.credentialSchemaProof = DocumentProof.toJSON(message.credentialSchemaProof); } - if (object.version_id !== undefined && object.version_id !== null) { - message.version_id = String(object.version_id); - } else { - message.version_id = ""; + if (message.txAuthor !== undefined && message.txAuthor !== "") { + obj.txAuthor = message.txAuthor; } - if (object.signatures !== undefined && object.signatures !== null) { - for (const e of object.signatures) { - message.signatures.push(SignInfo.fromJSON(e)); + return obj; + }, + + create, I>>(base?: I): MsgRegisterCredentialSchema { + return MsgRegisterCredentialSchema.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): MsgRegisterCredentialSchema { + const message = createBaseMsgRegisterCredentialSchema(); + message.credentialSchemaDocument = + (object.credentialSchemaDocument !== undefined && object.credentialSchemaDocument !== null) + ? CredentialSchemaDocument.fromPartial(object.credentialSchemaDocument) + : undefined; + message.credentialSchemaProof = + (object.credentialSchemaProof !== undefined && object.credentialSchemaProof !== null) + ? DocumentProof.fromPartial(object.credentialSchemaProof) + : undefined; + message.txAuthor = object.txAuthor ?? undefined; + return message; + }, +}; + +function createBaseMsgRegisterCredentialSchemaResponse(): MsgRegisterCredentialSchemaResponse { + return {}; +} + +export const MsgRegisterCredentialSchemaResponse = { + encode(_: MsgRegisterCredentialSchemaResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRegisterCredentialSchemaResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgRegisterCredentialSchemaResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break; } + reader.skipType(tag & 7); } return message; }, - toJSON(message: MsgDeactivateDID): unknown { + fromJSON(_: any): MsgRegisterCredentialSchemaResponse { + return {}; + }, + + toJSON(_: MsgRegisterCredentialSchemaResponse): unknown { const obj: any = {}; - message.creator !== undefined && (obj.creator = message.creator); - message.didId !== undefined && (obj.didId = message.didId); - message.version_id !== undefined && (obj.version_id = message.version_id); - if (message.signatures) { - obj.signatures = message.signatures.map((e) => - e ? SignInfo.toJSON(e) : undefined - ); - } else { - obj.signatures = []; - } return obj; }, - fromPartial(object: DeepPartial): MsgDeactivateDID { - const message = { ...baseMsgDeactivateDID } as MsgDeactivateDID; - message.signatures = []; - if (object.creator !== undefined && object.creator !== null) { - message.creator = object.creator; - } else { - message.creator = ""; + create, I>>( + base?: I, + ): MsgRegisterCredentialSchemaResponse { + return MsgRegisterCredentialSchemaResponse.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>( + _: I, + ): MsgRegisterCredentialSchemaResponse { + const message = createBaseMsgRegisterCredentialSchemaResponse(); + return message; + }, +}; + +function createBaseMsgUpdateCredentialSchema(): MsgUpdateCredentialSchema { + return {}; +} + +export const MsgUpdateCredentialSchema = { + encode(message: MsgUpdateCredentialSchema, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.credentialSchemaDocument !== undefined) { + CredentialSchemaDocument.encode(message.credentialSchemaDocument, writer.uint32(10).fork()).ldelim(); } - if (object.didId !== undefined && object.didId !== null) { - message.didId = object.didId; - } else { - message.didId = ""; + if (message.credentialSchemaProof !== undefined) { + DocumentProof.encode(message.credentialSchemaProof, writer.uint32(18).fork()).ldelim(); } - if (object.version_id !== undefined && object.version_id !== null) { - message.version_id = object.version_id; - } else { - message.version_id = ""; + if (message.txAuthor !== undefined && message.txAuthor !== "") { + writer.uint32(26).string(message.txAuthor); } - if (object.signatures !== undefined && object.signatures !== null) { - for (const e of object.signatures) { - message.signatures.push(SignInfo.fromPartial(e)); + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateCredentialSchema { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgUpdateCredentialSchema(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.credentialSchemaDocument = CredentialSchemaDocument.decode(reader, reader.uint32()); + continue; + case 2: + if (tag !== 18) { + break; + } + + message.credentialSchemaProof = DocumentProof.decode(reader, reader.uint32()); + continue; + case 3: + if (tag !== 26) { + break; + } + + message.txAuthor = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; } + reader.skipType(tag & 7); } return message; }, -}; -const baseMsgDeactivateDIDResponse: object = { id: 0 }; + fromJSON(object: any): MsgUpdateCredentialSchema { + return { + credentialSchemaDocument: isSet(object.credentialSchemaDocument) + ? CredentialSchemaDocument.fromJSON(object.credentialSchemaDocument) + : undefined, + credentialSchemaProof: isSet(object.credentialSchemaProof) + ? DocumentProof.fromJSON(object.credentialSchemaProof) + : undefined, + txAuthor: isSet(object.txAuthor) ? globalThis.String(object.txAuthor) : undefined, + }; + }, -export const MsgDeactivateDIDResponse = { - encode( - message: MsgDeactivateDIDResponse, - writer: Writer = Writer.create() - ): Writer { - if (message.id !== 0) { - writer.uint32(8).uint64(message.id); + toJSON(message: MsgUpdateCredentialSchema): unknown { + const obj: any = {}; + if (message.credentialSchemaDocument !== undefined) { + obj.credentialSchemaDocument = CredentialSchemaDocument.toJSON(message.credentialSchemaDocument); + } + if (message.credentialSchemaProof !== undefined) { + obj.credentialSchemaProof = DocumentProof.toJSON(message.credentialSchemaProof); } + if (message.txAuthor !== undefined && message.txAuthor !== "") { + obj.txAuthor = message.txAuthor; + } + return obj; + }, + + create, I>>(base?: I): MsgUpdateCredentialSchema { + return MsgUpdateCredentialSchema.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): MsgUpdateCredentialSchema { + const message = createBaseMsgUpdateCredentialSchema(); + message.credentialSchemaDocument = + (object.credentialSchemaDocument !== undefined && object.credentialSchemaDocument !== null) + ? CredentialSchemaDocument.fromPartial(object.credentialSchemaDocument) + : undefined; + message.credentialSchemaProof = + (object.credentialSchemaProof !== undefined && object.credentialSchemaProof !== null) + ? DocumentProof.fromPartial(object.credentialSchemaProof) + : undefined; + message.txAuthor = object.txAuthor ?? undefined; + return message; + }, +}; + +function createBaseMsgUpdateCredentialSchemaResponse(): MsgUpdateCredentialSchemaResponse { + return {}; +} + +export const MsgUpdateCredentialSchemaResponse = { + encode(_: MsgUpdateCredentialSchemaResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { return writer; }, - decode( - input: Reader | Uint8Array, - length?: number - ): MsgDeactivateDIDResponse { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateCredentialSchemaResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseMsgDeactivateDIDResponse, - } as MsgDeactivateDIDResponse; + const message = createBaseMsgUpdateCredentialSchemaResponse(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { - case 1: - message.id = longToNumber(reader.uint64() as Long); - break; - default: - reader.skipType(tag & 7); - break; } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); } return message; }, - fromJSON(object: any): MsgDeactivateDIDResponse { - const message = { - ...baseMsgDeactivateDIDResponse, - } as MsgDeactivateDIDResponse; - if (object.id !== undefined && object.id !== null) { - message.id = Number(object.id); - } else { - message.id = 0; - } - return message; + fromJSON(_: any): MsgUpdateCredentialSchemaResponse { + return {}; }, - toJSON(message: MsgDeactivateDIDResponse): unknown { + toJSON(_: MsgUpdateCredentialSchemaResponse): unknown { const obj: any = {}; - message.id !== undefined && (obj.id = message.id); return obj; }, - fromPartial( - object: DeepPartial - ): MsgDeactivateDIDResponse { - const message = { - ...baseMsgDeactivateDIDResponse, - } as MsgDeactivateDIDResponse; - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = 0; - } + create, I>>( + base?: I, + ): MsgUpdateCredentialSchemaResponse { + return MsgUpdateCredentialSchemaResponse.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>( + _: I, + ): MsgUpdateCredentialSchemaResponse { + const message = createBaseMsgUpdateCredentialSchemaResponse(); return message; }, }; -const baseMsgRegisterCredentialStatus: object = { creator: "" }; +function createBaseMsgRegisterCredentialStatus(): MsgRegisterCredentialStatus { + return {}; +} export const MsgRegisterCredentialStatus = { - encode( - message: MsgRegisterCredentialStatus, - writer: Writer = Writer.create() - ): Writer { - if (message.creator !== "") { - writer.uint32(10).string(message.creator); - } - if (message.credentialStatus !== undefined) { - CredentialStatus.encode( - message.credentialStatus, - writer.uint32(18).fork() - ).ldelim(); + encode(message: MsgRegisterCredentialStatus, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.credentialStatusDocument !== undefined) { + CredentialStatusDocument.encode(message.credentialStatusDocument, writer.uint32(10).fork()).ldelim(); } - if (message.proof !== undefined) { - CredentialProof.encode(message.proof, writer.uint32(26).fork()).ldelim(); + if (message.credentialStatusProof !== undefined) { + DocumentProof.encode(message.credentialStatusProof, writer.uint32(18).fork()).ldelim(); } - if (message.clientSpec !== undefined) { - ClientSpec.encode(message.clientSpec, writer.uint32(34).fork()).ldelim(); + if (message.txAuthor !== undefined && message.txAuthor !== "") { + writer.uint32(26).string(message.txAuthor); } return writer; }, - decode( - input: Reader | Uint8Array, - length?: number - ): MsgRegisterCredentialStatus { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRegisterCredentialStatus { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseMsgRegisterCredentialStatus, - } as MsgRegisterCredentialStatus; + const message = createBaseMsgRegisterCredentialStatus(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.creator = reader.string(); - break; + if (tag !== 10) { + break; + } + + message.credentialStatusDocument = CredentialStatusDocument.decode(reader, reader.uint32()); + continue; case 2: - message.credentialStatus = CredentialStatus.decode( - reader, - reader.uint32() - ); - break; + if (tag !== 18) { + break; + } + + message.credentialStatusProof = DocumentProof.decode(reader, reader.uint32()); + continue; case 3: - message.proof = CredentialProof.decode(reader, reader.uint32()); - break; - case 4: - message.clientSpec = ClientSpec.decode(reader, reader.uint32()); - break; - default: - reader.skipType(tag & 7); - break; + if (tag !== 26) { + break; + } + + message.txAuthor = reader.string(); + continue; } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); } return message; }, fromJSON(object: any): MsgRegisterCredentialStatus { - const message = { - ...baseMsgRegisterCredentialStatus, - } as MsgRegisterCredentialStatus; - if (object.creator !== undefined && object.creator !== null) { - message.creator = String(object.creator); - } else { - message.creator = ""; + return { + credentialStatusDocument: isSet(object.credentialStatusDocument) + ? CredentialStatusDocument.fromJSON(object.credentialStatusDocument) + : undefined, + credentialStatusProof: isSet(object.credentialStatusProof) + ? DocumentProof.fromJSON(object.credentialStatusProof) + : undefined, + txAuthor: isSet(object.txAuthor) ? globalThis.String(object.txAuthor) : undefined, + }; + }, + + toJSON(message: MsgRegisterCredentialStatus): unknown { + const obj: any = {}; + if (message.credentialStatusDocument !== undefined) { + obj.credentialStatusDocument = CredentialStatusDocument.toJSON(message.credentialStatusDocument); } - if ( - object.credentialStatus !== undefined && - object.credentialStatus !== null - ) { - message.credentialStatus = CredentialStatus.fromJSON( - object.credentialStatus - ); - } else { - message.credentialStatus = undefined; + if (message.credentialStatusProof !== undefined) { + obj.credentialStatusProof = DocumentProof.toJSON(message.credentialStatusProof); } - if (object.proof !== undefined && object.proof !== null) { - message.proof = CredentialProof.fromJSON(object.proof); - } else { - message.proof = undefined; + if (message.txAuthor !== undefined && message.txAuthor !== "") { + obj.txAuthor = message.txAuthor; } - if (object.clientSpec !== undefined && object.clientSpec !== null) { - message.clientSpec = ClientSpec.fromJSON(object.clientSpec); - } else { - message.clientSpec = undefined; + return obj; + }, + + create, I>>(base?: I): MsgRegisterCredentialStatus { + return MsgRegisterCredentialStatus.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): MsgRegisterCredentialStatus { + const message = createBaseMsgRegisterCredentialStatus(); + message.credentialStatusDocument = + (object.credentialStatusDocument !== undefined && object.credentialStatusDocument !== null) + ? CredentialStatusDocument.fromPartial(object.credentialStatusDocument) + : undefined; + message.credentialStatusProof = + (object.credentialStatusProof !== undefined && object.credentialStatusProof !== null) + ? DocumentProof.fromPartial(object.credentialStatusProof) + : undefined; + message.txAuthor = object.txAuthor ?? undefined; + return message; + }, +}; + +function createBaseMsgRegisterCredentialStatusResponse(): MsgRegisterCredentialStatusResponse { + return {}; +} + +export const MsgRegisterCredentialStatusResponse = { + encode(_: MsgRegisterCredentialStatusResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRegisterCredentialStatusResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgRegisterCredentialStatusResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); } return message; }, - toJSON(message: MsgRegisterCredentialStatus): unknown { + fromJSON(_: any): MsgRegisterCredentialStatusResponse { + return {}; + }, + + toJSON(_: MsgRegisterCredentialStatusResponse): unknown { const obj: any = {}; - message.creator !== undefined && (obj.creator = message.creator); - message.credentialStatus !== undefined && - (obj.credentialStatus = message.credentialStatus - ? CredentialStatus.toJSON(message.credentialStatus) - : undefined); - message.proof !== undefined && - (obj.proof = message.proof - ? CredentialProof.toJSON(message.proof) - : undefined); - message.clientSpec !== undefined && - (obj.clientSpec = message.clientSpec - ? ClientSpec.toJSON(message.clientSpec) - : undefined); return obj; }, - fromPartial( - object: DeepPartial - ): MsgRegisterCredentialStatus { - const message = { - ...baseMsgRegisterCredentialStatus, - } as MsgRegisterCredentialStatus; - if (object.creator !== undefined && object.creator !== null) { - message.creator = object.creator; - } else { - message.creator = ""; - } - if ( - object.credentialStatus !== undefined && - object.credentialStatus !== null - ) { - message.credentialStatus = CredentialStatus.fromPartial( - object.credentialStatus - ); - } else { - message.credentialStatus = undefined; - } - if (object.proof !== undefined && object.proof !== null) { - message.proof = CredentialProof.fromPartial(object.proof); - } else { - message.proof = undefined; - } - if (object.clientSpec !== undefined && object.clientSpec !== null) { - message.clientSpec = ClientSpec.fromPartial(object.clientSpec); - } else { - message.clientSpec = undefined; - } + create, I>>( + base?: I, + ): MsgRegisterCredentialStatusResponse { + return MsgRegisterCredentialStatusResponse.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>( + _: I, + ): MsgRegisterCredentialStatusResponse { + const message = createBaseMsgRegisterCredentialStatusResponse(); return message; }, }; -const baseMsgRegisterCredentialStatusResponse: object = { id: 0 }; +function createBaseMsgUpdateCredentialStatus(): MsgUpdateCredentialStatus { + return {}; +} -export const MsgRegisterCredentialStatusResponse = { - encode( - message: MsgRegisterCredentialStatusResponse, - writer: Writer = Writer.create() - ): Writer { - if (message.id !== 0) { - writer.uint32(8).uint64(message.id); +export const MsgUpdateCredentialStatus = { + encode(message: MsgUpdateCredentialStatus, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.credentialStatusDocument !== undefined) { + CredentialStatusDocument.encode(message.credentialStatusDocument, writer.uint32(10).fork()).ldelim(); + } + if (message.credentialStatusProof !== undefined) { + DocumentProof.encode(message.credentialStatusProof, writer.uint32(18).fork()).ldelim(); + } + if (message.txAuthor !== undefined && message.txAuthor !== "") { + writer.uint32(26).string(message.txAuthor); } return writer; }, - decode( - input: Reader | Uint8Array, - length?: number - ): MsgRegisterCredentialStatusResponse { - const reader = input instanceof Uint8Array ? new Reader(input) : input; + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateCredentialStatus { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); let end = length === undefined ? reader.len : reader.pos + length; - const message = { - ...baseMsgRegisterCredentialStatusResponse, - } as MsgRegisterCredentialStatusResponse; + const message = createBaseMsgUpdateCredentialStatus(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: - message.id = longToNumber(reader.uint64() as Long); - break; - default: - reader.skipType(tag & 7); - break; + if (tag !== 10) { + break; + } + + message.credentialStatusDocument = CredentialStatusDocument.decode(reader, reader.uint32()); + continue; + case 2: + if (tag !== 18) { + break; + } + + message.credentialStatusProof = DocumentProof.decode(reader, reader.uint32()); + continue; + case 3: + if (tag !== 26) { + break; + } + + message.txAuthor = reader.string(); + continue; } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): MsgUpdateCredentialStatus { + return { + credentialStatusDocument: isSet(object.credentialStatusDocument) + ? CredentialStatusDocument.fromJSON(object.credentialStatusDocument) + : undefined, + credentialStatusProof: isSet(object.credentialStatusProof) + ? DocumentProof.fromJSON(object.credentialStatusProof) + : undefined, + txAuthor: isSet(object.txAuthor) ? globalThis.String(object.txAuthor) : undefined, + }; + }, + + toJSON(message: MsgUpdateCredentialStatus): unknown { + const obj: any = {}; + if (message.credentialStatusDocument !== undefined) { + obj.credentialStatusDocument = CredentialStatusDocument.toJSON(message.credentialStatusDocument); + } + if (message.credentialStatusProof !== undefined) { + obj.credentialStatusProof = DocumentProof.toJSON(message.credentialStatusProof); + } + if (message.txAuthor !== undefined && message.txAuthor !== "") { + obj.txAuthor = message.txAuthor; } + return obj; + }, + + create, I>>(base?: I): MsgUpdateCredentialStatus { + return MsgUpdateCredentialStatus.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): MsgUpdateCredentialStatus { + const message = createBaseMsgUpdateCredentialStatus(); + message.credentialStatusDocument = + (object.credentialStatusDocument !== undefined && object.credentialStatusDocument !== null) + ? CredentialStatusDocument.fromPartial(object.credentialStatusDocument) + : undefined; + message.credentialStatusProof = + (object.credentialStatusProof !== undefined && object.credentialStatusProof !== null) + ? DocumentProof.fromPartial(object.credentialStatusProof) + : undefined; + message.txAuthor = object.txAuthor ?? undefined; return message; }, +}; - fromJSON(object: any): MsgRegisterCredentialStatusResponse { - const message = { - ...baseMsgRegisterCredentialStatusResponse, - } as MsgRegisterCredentialStatusResponse; - if (object.id !== undefined && object.id !== null) { - message.id = Number(object.id); - } else { - message.id = 0; +function createBaseMsgUpdateCredentialStatusResponse(): MsgUpdateCredentialStatusResponse { + return {}; +} + +export const MsgUpdateCredentialStatusResponse = { + encode(_: MsgUpdateCredentialStatusResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateCredentialStatusResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMsgUpdateCredentialStatusResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); } return message; }, - toJSON(message: MsgRegisterCredentialStatusResponse): unknown { + fromJSON(_: any): MsgUpdateCredentialStatusResponse { + return {}; + }, + + toJSON(_: MsgUpdateCredentialStatusResponse): unknown { const obj: any = {}; - message.id !== undefined && (obj.id = message.id); return obj; }, - fromPartial( - object: DeepPartial - ): MsgRegisterCredentialStatusResponse { - const message = { - ...baseMsgRegisterCredentialStatusResponse, - } as MsgRegisterCredentialStatusResponse; - if (object.id !== undefined && object.id !== null) { - message.id = object.id; - } else { - message.id = 0; - } + create, I>>( + base?: I, + ): MsgUpdateCredentialStatusResponse { + return MsgUpdateCredentialStatusResponse.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>( + _: I, + ): MsgUpdateCredentialStatusResponse { + const message = createBaseMsgUpdateCredentialStatusResponse(); return message; }, }; -/** Msg defines the Msg service. */ export interface Msg { - CreateDID(request: MsgCreateDID): Promise; + RegisterDID(request: MsgRegisterDID): Promise; UpdateDID(request: MsgUpdateDID): Promise; - CreateSchema(request: MsgCreateSchema): Promise; DeactivateDID(request: MsgDeactivateDID): Promise; - RegisterCredentialStatus( - request: MsgRegisterCredentialStatus - ): Promise; + RegisterCredentialSchema(request: MsgRegisterCredentialSchema): Promise; + UpdateCredentialSchema(request: MsgUpdateCredentialSchema): Promise; + RegisterCredentialStatus(request: MsgRegisterCredentialStatus): Promise; + UpdateCredentialStatus(request: MsgUpdateCredentialStatus): Promise; } +export const MsgServiceName = "hypersign.ssi.v1.Msg"; export class MsgClientImpl implements Msg { private readonly rpc: Rpc; - constructor(rpc: Rpc) { + private readonly service: string; + constructor(rpc: Rpc, opts?: { service?: string }) { + this.service = opts?.service || MsgServiceName; this.rpc = rpc; + this.RegisterDID = this.RegisterDID.bind(this); + this.UpdateDID = this.UpdateDID.bind(this); + this.DeactivateDID = this.DeactivateDID.bind(this); + this.RegisterCredentialSchema = this.RegisterCredentialSchema.bind(this); + this.UpdateCredentialSchema = this.UpdateCredentialSchema.bind(this); + this.RegisterCredentialStatus = this.RegisterCredentialStatus.bind(this); + this.UpdateCredentialStatus = this.UpdateCredentialStatus.bind(this); } - CreateDID(request: MsgCreateDID): Promise { - const data = MsgCreateDID.encode(request).finish(); - const promise = this.rpc.request( - "hypersignprotocol.hidnode.ssi.Msg", - "CreateDID", - data - ); - return promise.then((data) => - MsgCreateDIDResponse.decode(new Reader(data)) - ); + RegisterDID(request: MsgRegisterDID): Promise { + const data = MsgRegisterDID.encode(request).finish(); + const promise = this.rpc.request(this.service, "RegisterDID", data); + return promise.then((data) => MsgRegisterDIDResponse.decode(_m0.Reader.create(data))); } UpdateDID(request: MsgUpdateDID): Promise { const data = MsgUpdateDID.encode(request).finish(); - const promise = this.rpc.request( - "hypersignprotocol.hidnode.ssi.Msg", - "UpdateDID", - data - ); - return promise.then((data) => - MsgUpdateDIDResponse.decode(new Reader(data)) - ); - } - - CreateSchema(request: MsgCreateSchema): Promise { - const data = MsgCreateSchema.encode(request).finish(); - const promise = this.rpc.request( - "hypersignprotocol.hidnode.ssi.Msg", - "CreateSchema", - data - ); - return promise.then((data) => - MsgCreateSchemaResponse.decode(new Reader(data)) - ); + const promise = this.rpc.request(this.service, "UpdateDID", data); + return promise.then((data) => MsgUpdateDIDResponse.decode(_m0.Reader.create(data))); } DeactivateDID(request: MsgDeactivateDID): Promise { const data = MsgDeactivateDID.encode(request).finish(); - const promise = this.rpc.request( - "hypersignprotocol.hidnode.ssi.Msg", - "DeactivateDID", - data - ); - return promise.then((data) => - MsgDeactivateDIDResponse.decode(new Reader(data)) - ); + const promise = this.rpc.request(this.service, "DeactivateDID", data); + return promise.then((data) => MsgDeactivateDIDResponse.decode(_m0.Reader.create(data))); + } + + RegisterCredentialSchema(request: MsgRegisterCredentialSchema): Promise { + const data = MsgRegisterCredentialSchema.encode(request).finish(); + const promise = this.rpc.request(this.service, "RegisterCredentialSchema", data); + return promise.then((data) => MsgRegisterCredentialSchemaResponse.decode(_m0.Reader.create(data))); } - RegisterCredentialStatus( - request: MsgRegisterCredentialStatus - ): Promise { + UpdateCredentialSchema(request: MsgUpdateCredentialSchema): Promise { + const data = MsgUpdateCredentialSchema.encode(request).finish(); + const promise = this.rpc.request(this.service, "UpdateCredentialSchema", data); + return promise.then((data) => MsgUpdateCredentialSchemaResponse.decode(_m0.Reader.create(data))); + } + + RegisterCredentialStatus(request: MsgRegisterCredentialStatus): Promise { const data = MsgRegisterCredentialStatus.encode(request).finish(); - const promise = this.rpc.request( - "hypersignprotocol.hidnode.ssi.Msg", - "RegisterCredentialStatus", - data - ); - return promise.then((data) => - MsgRegisterCredentialStatusResponse.decode(new Reader(data)) - ); + const promise = this.rpc.request(this.service, "RegisterCredentialStatus", data); + return promise.then((data) => MsgRegisterCredentialStatusResponse.decode(_m0.Reader.create(data))); + } + + UpdateCredentialStatus(request: MsgUpdateCredentialStatus): Promise { + const data = MsgUpdateCredentialStatus.encode(request).finish(); + const promise = this.rpc.request(this.service, "UpdateCredentialStatus", data); + return promise.then((data) => MsgUpdateCredentialStatusResponse.decode(_m0.Reader.create(data))); } } interface Rpc { - request( - service: string, - method: string, - data: Uint8Array - ): Promise; + request(service: string, method: string, data: Uint8Array): Promise; } -declare var self: any | undefined; -declare var window: any | undefined; -var globalThis: any = (() => { - if (typeof globalThis !== "undefined") return globalThis; - if (typeof self !== "undefined") return self; - if (typeof window !== "undefined") return window; - if (typeof global !== "undefined") return global; - throw "Unable to locate global object"; -})(); - -type Builtin = Date | Function | Uint8Array | string | number | undefined; -export type DeepPartial = T extends Builtin - ? T - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends globalThis.Array ? globalThis.Array> + : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } : Partial; -function longToNumber(long: Long): number { - if (long.gt(Number.MAX_SAFE_INTEGER)) { - throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); - } - return long.toNumber(); -} +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; -// if (util.Long !== Long) { -// util.Long = Long as any; -// configure(); -// } +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/package.json b/package.json index ca60dea..93dd4b8 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "@digitalbazaar/ed25519-signature-2020": "^3.0.0", "@digitalbazaar/ed25519-verification-key-2018": "^3.1.2", "@digitalbazaar/ed25519-verification-key-2020": "^3.3.0", + "@iden3/js-jsonld-merklization": "^1.0.2", "@stablelib/ed25519": "^1.0.2", "axios": "^0.19.0", "crypto-ld": "^6.0.0", @@ -38,6 +39,7 @@ "jsonld": "^8.2.0", "jsonld-signatures": "^9.3.1", "jsonwebtoken": "^9.0.1", + "multiformats": "^9.9.0", "node-fetch": "^2.6.1", "protobufjs": "^6.11.2", "uuid": "^8.3.0", diff --git a/src/constants.ts b/src/constants.ts index 9e1f9a0..48b9e75 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,5 @@ 'use strict'; +import { ProofTypes, VerificationMethodRelationships, VerificationMethodTypes } from "../libs/generated/ssi/client/enums"; export const compactProof = false; export const HYPERSIGN_TESTNET_RPC = 'https://rpc.jagrat.hypersign.id'; @@ -7,31 +8,32 @@ export const HYPERSIGN_TESTNET_REST = 'https://api.jagrat.hypersign.id'; export const HYPERSIGN_MAINNET_RPC = 'http://localhost:26657'; export const HYPERSIGN_MAINNET_REST = 'http://localhost:1317'; -export const HID_COSMOS_MODULE = '/hypersignprotocol.hidnode.ssi'; +export const HID_COSMOS_MODULE = '/hypersign.ssi.v1'; export const HYPERSIGN_NETWORK_DID_PATH = 'hypersign-protocol/hidnode/ssi/did'; export const HYPERSIGN_NETWORK_SCHEMA_PATH = 'hypersign-protocol/hidnode/ssi/schema'; export const HYPERSIGN_NETWORK_CREDENTIALSTATUS_PATH = 'hypersign-protocol/hidnode/ssi/credential'; export const HYPERSIGN_NETWORK_BANK_BALANCE_PATH = '/bank/balances/'; export enum HIDRpcEnums { - MsgCreateDID = 'MsgCreateDID', + MsgRegisterDID = 'MsgRegisterDID', MsgUpdateDID = 'MsgUpdateDID', MsgDeactivateDID = 'MsgDeactivateDID', - MsgCreateSchema = 'MsgCreateSchema', + MsgRegisterCredentialSchema = 'MsgRegisterCredentialSchema', MsgRegisterCredentialStatus = 'MsgRegisterCredentialStatus', + MsgUpdateCredentialStatus = "MsgUpdateCredentialStatus" } Object.freeze(HIDRpcEnums); export enum CredentialStatusEnums { - LIVE = "Live", - REVOKED="Revoked", - SUSPENDED="Suspended" + LIVE = "Live", + REVOKED = "Revoked", + SUSPENDED = "Suspended" } export enum CredentialStatusReasonEnums { - LIVE = "Credential is live", - REVOKED="Credential is revoked", - SUSPENDED="Credential is suspended" + LIVE = "Credential is live", + REVOKED = "Credential is revoked", + SUSPENDED = "Credential is suspended" } @@ -43,10 +45,10 @@ export const DID_Ed25519VerificationKey2020 = { METHOD: 'hid', NAMESPACE: 'testnet', // this is not used DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1', - DID_KEYAGREEMENT_CONTEXT:"https://digitalbazaar.github.io/x25519-key-agreement-2020-context/contexts/x25519-key-agreement-2020-v1.jsonld", + DID_KEYAGREEMENT_CONTEXT: "https://digitalbazaar.github.io/x25519-key-agreement-2020-context/contexts/x25519-key-agreement-2020-v1.jsonld", VERIFICATION_METHOD_TYPE: 'Ed25519VerificationKey2020', BLOCKCHAINACCOUNTID_CONTEXT: 'https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.jsonld', - + SIGNATURE_TYPE: ProofTypes.Ed25519Signature2020, }; @@ -56,9 +58,10 @@ export const DID_EcdsaSecp256k1RecoveryMethod2020 = { METHOD: 'hid', NAMESPACE: 'testnet', // this is not used DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1', - DID_KEYAGREEMENT_CONTEXT:"https://github.com/hypersign-protocol/hid-ssi-js-sdk/blob/develop/libs/w3cache/v1/X25519KeyAgreementKeyEIP5630.json", + DID_KEYAGREEMENT_CONTEXT: "https://github.com/hypersign-protocol/hid-ssi-js-sdk/blob/develop/libs/w3cache/v1/X25519KeyAgreementKeyEIP5630.json", BLOCKCHAINACCOUNTID_CONTEXT: 'https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.jsonld', - VERIFICATION_METHOD_TYPE: 'EcdsaSecp256k1RecoveryMethod2020', + VERIFICATION_METHOD_TYPE: VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020, + SIGNATURE_TYPE: ProofTypes.EcdsaSecp256k1RecoverySignature2020, }; @@ -70,12 +73,13 @@ export const DID_EcdsaSecp256k1VerificationKey2019 = { NAMESPACE: 'testnet', // this is not used DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1', BLOCKCHAINACCOUNTID_CONTEXT: 'https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.jsonld', - VERIFICATION_METHOD_TYPE: 'EcdsaSecp256k1VerificationKey2019', + VERIFICATION_METHOD_TYPE: VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019, + SIGNATURE_TYPE: ProofTypes.EcdsaSecp256k1Signature2019, }; -export enum CAIP_10_PREFIX{ - "eip155"="eip155", +export enum CAIP_10_PREFIX { + "eip155" = "eip155", } @@ -85,7 +89,7 @@ export const DID = { METHOD: 'hid', NAMESPACE: 'testnet', // this is not used DID_BASE_CONTEXT: 'https://www.w3.org/ns/did/v1', - VERIFICATION_METHOD_TYPE: 'Ed25519VerificationKey2020', + VERIFICATION_METHOD_TYPE: VerificationMethodTypes.Ed25519VerificationKey2020, BLOCKCHAINACCOUNTID_CONTEXT: 'https://w3c.github.io/vc-data-integrity/vocab/security/vocabulary.jsonld', }; @@ -94,21 +98,31 @@ Object.freeze(DID); export const VC = { - SCHEME: "vc", - METHOD: "hid", - NAMESPACE:"testnet", - PREFIX: "vc:" + DID.METHOD + ":" + DID.NAMESPACE + ":", - CREDENTAIL_SCHEMA_VALIDATOR_TYPE: "JsonSchemaValidator2018", - CREDENTAIL_STATUS_TYPE: "CredentialStatusList2017", - CREDENTAIL_BASE_CONTEXT: "https://www.w3.org/2018/credentials/v1", - CREDENTAIL_SECURITY_CONTEXT_V2: "https://w3id.org/security/v2", - CREDENTAIL_SECURITY_SUITE: "https://w3id.org/security/suites/ed25519-2020/v1", - CREDENTAIL_ECDSA_SECURITY_SUITE: "https://w3id.org/security/suites/secp256k1recovery-2020/v2", - PROOF_PURPOSE: "assertion", - VERIFICATION_METHOD_TYPE: "Ed25519Signature2020", - CRED_STATUS_TYPES: CredentialStatusEnums , - - CRED_STATUS_REASON_TYPES: CredentialStatusReasonEnums + SCHEME: "vc", + METHOD: "hid", + NAMESPACE: "testnet", + PREFIX: "vc:" + DID.METHOD + ":" + DID.NAMESPACE + ":", + CREDENTAIL_SCHEMA_VALIDATOR_TYPE: "JsonSchemaValidator2018", + CREDENTAIL_STATUS_TYPE: "HypersignCredentialStatus2023", + CONTEXT_HypersignCredentialStatus2023: { + "@protected": true, + "HypersignCredentialStatus2023": { + "@id": "https://hypersign.id#HypersignCredentialStatus2023", + "@context": { + "@protected": true, + "id": "@id", + "type": "@type" + } + } + },// will change this to url later + CREDENTAIL_BASE_CONTEXT: "https://www.w3.org/2018/credentials/v1", + CREDENTAIL_SECURITY_CONTEXT_V2: "https://w3id.org/security/v2", + CREDENTAIL_SECURITY_SUITE: "https://w3id.org/security/suites/ed25519-2020/v1", + CREDENTAIL_ECDSA_SECURITY_SUITE: "https://w3id.org/security/suites/secp256k1recovery-2020/v2", + PROOF_PURPOSE: VerificationMethodRelationships.assertionMethod, + VERIFICATION_METHOD_TYPE: ProofTypes.Ed25519Signature2020, + CRED_STATUS_TYPES: CredentialStatusEnums, + CRED_STATUS_REASON_TYPES: CredentialStatusReasonEnums } Object.freeze(VC) @@ -126,8 +140,8 @@ export const SCHEMA = { NAMESPACE: 'testnet', SCHEMA_JSON: 'http://json-schema.org/draft-07/schema', SCHEMA_TYPE: 'https://w3c-ccg.github.io/vc-json-schemas/v1/schema/1.0/schema.json', - SIGNATURE_TYPE: "Ed25519Signature2020", - PROOF_PURPOSE: "assertion", + SIGNATURE_TYPE: ProofTypes.Ed25519Signature2020, + PROOF_PURPOSE: VerificationMethodRelationships.assertionMethod, }; Object.freeze(SCHEMA); diff --git a/src/credential/ICredential.ts b/src/credential/ICredential.ts index 08832fd..18932e4 100644 --- a/src/credential/ICredential.ts +++ b/src/credential/ICredential.ts @@ -5,7 +5,12 @@ */ import { TypedDataField } from '@ethersproject/abstract-signer'; -import { CredentialStatus, CredentialProof, Credential } from '../../libs/generated/ssi/credential'; +import { + CredentialStatusDocument as CredentialStatus, + CredentialStatusState as Credential, +} from '../../libs/generated/ssi/credential_status'; +import { DocumentProof as CredentialProof } from '../../libs/generated/ssi/proof'; + import { DeliverTxResponse } from '@cosmjs/stargate'; // interface ICredStatus { @@ -96,10 +101,14 @@ export interface ICredentialMethods { statusReason?: string; }): Promise; - resolveCredentialStatus(params: { credentialId: string }): Promise; + resolveCredentialStatus(params: { credentialId: string }): Promise; checkCredentialStatus(params: { credentialId: string }): Promise<{ verified: boolean }>; } +export interface IResolveCredential extends CredentialStatus { + proof: CredentialProof; +} + export interface ICredentialRPC { credentialRestEP: string; registerCredentialStatus(credentialStatus: CredentialStatus, proof: CredentialProof): Promise; diff --git a/src/credential/credRPC.ts b/src/credential/credRPC.ts index 4990f27..cf2a79d 100644 --- a/src/credential/credRPC.ts +++ b/src/credential/credRPC.ts @@ -10,7 +10,11 @@ import { SigningStargateClient, DeliverTxResponse } from '@cosmjs/stargate'; import axios from 'axios'; import { HIDClient } from '../hid/client'; import { ICredentialRPC } from './ICredential'; -import { CredentialStatus, CredentialProof, Credential } from '../../libs/generated/ssi/credential'; +import { + CredentialStatusDocument as CredentialStatus, + CredentialStatusState as Credential, +} from '../../libs/generated/ssi/credential_status'; +import { DocumentProof as CredentialProof } from '../../libs/generated/ssi/proof'; import { OfflineSigner } from '@cosmjs/proto-signing'; export class CredentialRPC implements ICredentialRPC { @@ -64,9 +68,9 @@ export class CredentialRPC implements ICredentialRPC { const txMessage = { typeUrl, // Same as above value: generatedProto[HIDRpcEnums.MsgRegisterCredentialStatus].fromPartial({ - credentialStatus, - proof, - creator: HIDClient.getHidWalletAddress(), + credentialStatusDocument: credentialStatus, + credentialStatusProof: proof, + txAuthor: HIDClient.getHidWalletAddress(), }), }; @@ -94,9 +98,9 @@ export class CredentialRPC implements ICredentialRPC { const txMessage = { typeUrl, // Same as above value: generatedProto[HIDRpcEnums.MsgRegisterCredentialStatus].fromPartial({ - credentialStatus, - proof, - creator: HIDClient.getHidWalletAddress(), + credentialStatusDocument: credentialStatus, + credentialStatusProof: proof, + txAuthor: HIDClient.getHidWalletAddress(), }), }; @@ -127,8 +131,8 @@ export class CredentialRPC implements ICredentialRPC { if (!response.data) { throw new Error('Could not resolve credential status of credentialId ' + credentialId); } - const credStatus: Credential = response.data.credStatus; - if (!credStatus || !credStatus.claim || !credStatus.proof) { + const credStatus: Credential = response.data.credentialStatus; + if (!credStatus || !credStatus.credentialStatusDocument || !credStatus.credentialStatusProof) { throw new Error('No credential status found. Probably invalid credentialId'); } return credStatus; @@ -141,10 +145,43 @@ export class CredentialRPC implements ICredentialRPC { credentialHash: '', proof: null, } as any as Credential; - if (!credStatus || !credStatus.claim || !credStatus.proof) { + if (!credStatus || !credStatus.credentialStatusDocument || !credStatus.credentialStatusProof) { throw new Error('No credential status found. Probably invalid credentialId'); } return credStatus; } } + async updateCredentialStatus(credentialStatus: CredentialStatus, proof: CredentialProof): Promise { + if (!credentialStatus) { + throw new Error('CredentialStatus must be passed as a param while registerting credential status'); + } + + if (!proof) { + throw new Error('Proof must be passed as a param while registering crdential status'); + } + + if (!this.hidClient) { + throw new Error('HID-SSI-SDK:: Error: CredentialRPC class is not initialise with offlinesigner'); + } + + const typeUrl = `${HID_COSMOS_MODULE}.${HIDRpcEnums.MsgUpdateCredentialStatus}`; + + const txMessage = { + typeUrl, + value: generatedProto[HIDRpcEnums.MsgUpdateCredentialStatus].fromPartial({ + credentialStatusDocument: credentialStatus, + credentialStatusProof: proof, + txAuthor: HIDClient.getHidWalletAddress(), + }), + }; + + const fee = 'auto'; + const hidClient: SigningStargateClient = HIDClient.getHidClient(); + const txResult: DeliverTxResponse = await hidClient.signAndBroadcast( + HIDClient.getHidWalletAddress(), + [txMessage], + fee + ); + return txResult; + } } diff --git a/src/credential/vc.ts b/src/credential/vc.ts index 4de5e31..c1095ee 100644 --- a/src/credential/vc.ts +++ b/src/credential/vc.ts @@ -7,16 +7,31 @@ import { purposes } from 'jsonld-signatures'; import vc from 'vc-js'; import Utils from '../utils'; import HypersignSchema from '../schema/schema'; -import { Schema, SchemaProperty } from '../../libs/generated/ssi/schema'; +import { + CredentialSchemaState as Schema, + CredentialSchemaProperty as SchemaProperty, +} from '../../libs/generated/ssi/credential_schema'; import HypersignDID from '../did/did'; -import { Did, VerificationMethod } from '../../libs/generated/ssi/did'; +import { DidDocument as Did, VerificationMethod } from '../../libs/generated/ssi/did'; import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020'; import { Ed25519Signature2020 } from '@digitalbazaar/ed25519-signature-2020'; const ed25519 = require('@stablelib/ed25519'); import { CredentialRPC } from './credRPC'; -import { ICredentialMethods, IVerifiableCredential, ICredentialStatus, ISchema, ICredentialProof } from './ICredential'; -import { VC, DID } from '../constants'; -import { CredentialStatus, CredentialProof, Credential, Claim } from '../../libs/generated/ssi/credential'; +import { + ICredentialMethods, + IVerifiableCredential, + ICredentialStatus, + ISchema, + ICredentialProof, + IResolveCredential, +} from './ICredential'; +import { VC, DID, CredentialStatusEnums } from '../constants'; +import { + CredentialStatusDocument as CredentialStatus, + CredentialStatusDocument, + CredentialStatusState, +} from '../../libs/generated/ssi/credential_status'; +import { DocumentProof as CredentialProof } from '../../libs/generated/ssi/proof'; import { DeliverTxResponse } from '@cosmjs/stargate'; import { OfflineSigner } from '@cosmjs/proto-signing'; import crypto from 'crypto'; @@ -26,7 +41,9 @@ import { IClientSpec } from '../did/IDID'; import { extendContextLoader } from 'jsonld-signatures'; import { ICredentialService } from '../ssiApi/services/credential/ICredentialApi'; import CredentialApiService from '../ssiApi/services/credential/credential.service'; - +import { IResolveSchema } from '../schema/ISchema'; +import { base58btc } from 'multiformats/bases/base58'; +const { Merklizer, MtValue } = require('@iden3/js-jsonld-merklization'); const documentLoader = extendContextLoader(customLoader); export default class HypersignVerifiableCredential implements ICredentialMethods, IVerifiableCredential { @@ -100,7 +117,8 @@ export default class HypersignVerifiableCredential implements ICredentialMethods const credentialBytes = (await CredentialStatus.encode(credentialStatus)).finish(); // const messageBytes = Buffer.from(params.message); const signed = ed25519.sign(privateKeyMultibaseConverted, credentialBytes); - return Buffer.from(signed).toString('base64'); + // return Buffer.from(signed).toString('base64'); + return base58btc.encode(signed); } private _dateNow(date?: string): string { @@ -153,7 +171,7 @@ export default class HypersignVerifiableCredential implements ICredentialMethods } // Check all required propes - const requiredPros: Array = Object.values(schemaProperty.required); + const requiredPros: Array = Object.values(schemaProperty.required as string[]); if (!this._checkIfAllRequiredPropsAreSent(sentPropes, requiredPros)) throw new Error(`${JSON.stringify(requiredPros)} are required properties`); @@ -168,7 +186,7 @@ export default class HypersignVerifiableCredential implements ICredentialMethods // // TODO: https://www.w3.org/TR/vc-data-model/#data-schemas // TODO: handle schemaUrl variable properly later. - private _getCredentialContext = (schemaId: string, schemaProperties: object) => { + private _getCredentialContext = (schemaId: string, schemaProperties: object, schemaName: string) => { const context: any = []; let schemaUrl; @@ -179,22 +197,28 @@ export default class HypersignVerifiableCredential implements ICredentialMethods } context.push(VC.CREDENTAIL_BASE_CONTEXT); - //context.push(VC.CREDENTAIL_SECURITY_SUITE); + // context.push(VC.CREDENTAIL_SECURITY_SUITE); context.push({ hs: schemaUrl, }); - + context.push({ + [schemaName]: `hs:${schemaName}`, + }); const props: Array = Object.keys(schemaProperties); props.forEach((x) => { const obj = {}; obj[x] = `hs:${x}`; context.push(obj); }); + context.push(VC.CONTEXT_HypersignCredentialStatus2023); return context; }; + private async _toTitleCase(status: string) { + return status.charAt(0).toUpperCase() + status.slice(1).toLowerCase(); + } /** * Initialise the offlinesigner to interact with Hypersign blockchain */ @@ -234,7 +258,7 @@ export default class HypersignVerifiableCredential implements ICredentialMethods expirationDate: string; fields: object; }): Promise { - let schemaDoc: Schema = {} as Schema; + let schemaDoc: IResolveSchema = {} as IResolveSchema; if (params.subjectDid && params.subjectDidDocSigned) { throw new Error('HID-SSI-SDK:: Error: Both subjectDid and subjectDidDoc cannot be passed'); } @@ -249,7 +273,6 @@ export default class HypersignVerifiableCredential implements ICredentialMethods const subjectDid = params.subjectDid; let resolvedsubjectDidDoc; const { didDocument: issuerDidDoc } = await this.hsDid.resolve({ did: issuerDid }); - // if (params.subjectDid) { resolvedsubjectDidDoc = await this.hsDid.resolve({ did: params.subjectDid }); } else if (params.subjectDidDocSigned) { @@ -322,17 +345,17 @@ export default class HypersignVerifiableCredential implements ICredentialMethods const vc: IVerifiableCredential = {} as IVerifiableCredential; const schemaInternal = schemaDoc.schema as SchemaProperty; - const schemaProperties = JSON.parse(schemaInternal.properties); + const schemaProperties = JSON.parse(schemaInternal.properties as string); + const schemaName = schemaDoc.name as string; // context - vc['@context'] = this._getCredentialContext(params.schemaId, schemaProperties); - + vc['@context'] = this._getCredentialContext(params.schemaId, schemaProperties, schemaName); /// TODO: need to implement this properly vc.id = await this._getId(); // Type vc.type = []; vc.type.push('VerifiableCredential'); - vc.type.push(schemaDoc.name); + vc.type.push(schemaDoc.name as string); vc.expirationDate = this._dateNow(params.expirationDate); vc.issuanceDate = this._dateNow(); // TODO: need to remove this. @@ -344,7 +367,7 @@ export default class HypersignVerifiableCredential implements ICredentialMethods }; vc.credentialSubject['id'] = subjectDid && subjectDid != undefined ? subjectDid : subjectDidDoc.id; vc.credentialSchema = { - id: schemaDoc.id, + id: schemaDoc.id as string, type: this.credentialSchema.type, }; @@ -427,12 +450,6 @@ export default class HypersignVerifiableCredential implements ICredentialMethods ); } - const convertedKeyPair = Utils.convertedStableLibKeysIntoEd25519verificationkey2020({ - publicKey: publicKeyVerMethod.publicKeyMultibase, - }); - - publicKeyVerMethod['publicKeyMultibase'] = convertedKeyPair.publicKeyMultibase; - const keyPair = await Ed25519VerificationKey2020.from({ privateKeyMultibase: params.privateKeyMultibase, ...publicKeyVerMethod, @@ -446,49 +463,44 @@ export default class HypersignVerifiableCredential implements ICredentialMethods /// Before we issue the credential the credential status has to be added /// for that we will call RegisterCredentialStatus RPC // Let us generate credentialHash first - const credentialHash = this._sha256Hash(JSON.stringify(params.credential)); + + // generating hash using merkelroot hash + + const merkelizerObj = await Merklizer.merklizeJSONLD(JSON.stringify(params.credential)); + let credentialHash = await merkelizerObj.mt.root(); + credentialHash = Buffer.from(credentialHash.bytes).toString('hex'); const credentialStatus: CredentialStatus = { - claim: { - id: params.credential.id, - currentStatus: VC.CRED_STATUS_TYPES.LIVE, - statusReason: 'Credential is active', - }, + id: params.credential.id, issuer: params.credential.issuer, issuanceDate: params.credential.issuanceDate, - expirationDate: params.credential.expirationDate, - credentialHash, + revoked: false, + suspended: false, + remarks: 'Credential is active', + credentialMerkleRootHash: credentialHash, }; const proofValue = await this._sign({ message: JSON.stringify(credentialStatus), privateKeyMultibase: params.privateKeyMultibase, }); - // check params.issuer is a controller of params.credential.issuer const { didDocument: issuerDID } = await this.hsDid.resolve({ did: params.credential.issuer }); if (issuerDID === null || issuerDID === undefined) throw new Error('Could not resolve issuerDid = ' + params.credential.issuer); const credIssuerDidDoc: Did = issuerDID as Did; - const credIssuerController = credIssuerDidDoc.controller; + const credIssuerController = credIssuerDidDoc.controller as string[]; if (!credIssuerController.includes(params.issuerDid)) { throw new Error(params.issuerDid + ' is not a controller of ' + params.credential.issuer); } - // const issuerDidDoc: Did = issuerDID as Did; - // const issuerPublicKeyId = params.verificationMethodId; - // const issuerPublicKeyVerMethod: VerificationMethod = issuerDidDoc.verificationMethod.find( - // (x) => x.id == issuerPublicKeyId - // ) as VerificationMethod; - const issuerPublicKeyVerMethod: VerificationMethod = publicKeyVerMethod; const proof: CredentialProof = { type: VC.VERIFICATION_METHOD_TYPE, created: this._dateNow(), - updated: this._dateNow(), - verificationMethod: issuerPublicKeyVerMethod.id, + verificationMethod: issuerPublicKeyVerMethod.id as string, proofValue, proofPurpose: VC.PROOF_PURPOSE, }; @@ -554,17 +566,10 @@ export default class HypersignVerifiableCredential implements ICredentialMethods const { didDocument: issuerDID } = await this.hsDid.resolve({ did: params.issuerDid }); const issuerDidDoc: Did = issuerDID as Did; const publicKeyId = params.verificationMethodId; - const publicKeyVerMethod: VerificationMethod = issuerDidDoc.verificationMethod.find( + const publicKeyVerMethod: VerificationMethod = (issuerDidDoc.verificationMethod as VerificationMethod[]).find( (x) => x.id == publicKeyId ) as VerificationMethod; - // TODO: Get rid of this hack later. - // Convert 45 byte publick key into 48 - const { publicKeyMultibase } = Utils.convertedStableLibKeysIntoEd25519verificationkey2020({ - publicKey: publicKeyVerMethod.publicKeyMultibase, - }); - publicKeyVerMethod.publicKeyMultibase = publicKeyMultibase; - const assertionController = { '@context': DID.CONTROLLER_CONTEXT, id: issuerDidDoc.id, @@ -600,19 +605,23 @@ export default class HypersignVerifiableCredential implements ICredentialMethods * Resolves credential status from Hypersign Blokchain * @params * - params.credentialId : Verifiable credential id - * @returns {Promise} + * @returns {Promise} */ - public async resolveCredentialStatus(params: { credentialId: string }): Promise { + public async resolveCredentialStatus(params: { credentialId: string }): Promise { if (!params || !params.credentialId) throw new Error('HID-SSI-SDK:: Error: params.credentialId is required to resolve credential status'); - let credentialStatus = {} as CredentialStatus; + let credentialStatus = {} as CredentialStatusState; if (!this.credStatusRPC) { throw new Error( 'HID-SSI-SDK:: Error: HypersignVerifiableCred is not instantiated with Offlinesigner or not initialized' ); } credentialStatus = await this.credStatusRPC.resolveCredentialStatus(params.credentialId); - return credentialStatus; + const response = { + ...(credentialStatus.credentialStatusDocument as CredentialStatusDocument), + proof: credentialStatus.credentialStatusProof as CredentialProof, + }; + return response; } /** @@ -652,7 +661,6 @@ export default class HypersignVerifiableCredential implements ICredentialMethods if (!params.status) { throw new Error('HID-SSI-SDK:: Error: params.status is required to update credential status'); } - if (!this.credStatusRPC) { throw new Error( 'HID-SSI-SDK:: Error: HypersignVerifiableCredential class is not instantiated with Offlinesigner or have not been initilized' @@ -668,12 +676,6 @@ export default class HypersignVerifiableCredential implements ICredentialMethods (x) => x.id == publicKeyId ) as VerificationMethod; - const convertedKeyPair = Utils.convertedStableLibKeysIntoEd25519verificationkey2020({ - publicKey: publicKeyVerMethod.publicKeyMultibase, - }); - - publicKeyVerMethod['publicKeyMultibase'] = convertedKeyPair.publicKeyMultibase; - const keyPair = await Ed25519VerificationKey2020.from({ privateKeyMultibase: params.privateKeyMultibase, ...publicKeyVerMethod, @@ -687,18 +689,38 @@ export default class HypersignVerifiableCredential implements ICredentialMethods /// Before we issue the credential the credential status has to be added /// for that we will call RegisterCredentialStatus RPC // Let us generate credentialHash first - params.status = params.status.toUpperCase(); - const claim: Claim = params.credentialStatus.claim as Claim; + const status = await this._toTitleCase(params.status); + if (!Object.values(CredentialStatusEnums).includes(status as CredentialStatusEnums)) { + throw new Error(`HID-SSI-SDK:: Error: params.status is invalid`); + } + + let revoked = false; + let suspended = false; + if (status === VC.CRED_STATUS_TYPES.REVOKED) { + revoked = true; + } else if (status === VC.CRED_STATUS_TYPES.SUSPENDED) { + suspended = true; + } else if (status === VC.CRED_STATUS_TYPES.LIVE) { + revoked = false; + suspended = false; + } + + /** + * TODO:- + * check if credential is already suspended + * check if credential is already Live + * should not update a credential if it is revoked + */ + + const claim = params.credentialStatus; const credentialStatus: CredentialStatus = { - claim: { - id: claim.id, - currentStatus: VC.CRED_STATUS_TYPES[params.status], - statusReason: params.statusReason ? params.statusReason : VC.CRED_STATUS_REASON_TYPES[params.status], - }, + id: claim.id, + revoked, + suspended, + remarks: params.statusReason ?? VC.CRED_STATUS_REASON_TYPES[params.status], issuer: params.credentialStatus.issuer, issuanceDate: params.credentialStatus.issuanceDate, - expirationDate: params.credentialStatus.expirationDate, - credentialHash: params.credentialStatus.credentialHash, + credentialMerkleRootHash: params.credentialStatus.credentialMerkleRootHash, }; const proofValue = await this._sign({ @@ -706,9 +728,9 @@ export default class HypersignVerifiableCredential implements ICredentialMethods privateKeyMultibase: params.privateKeyMultibase, }); - const { didDocument: issuerDID } = await this.hsDid.resolve({ did: params.credentialStatus.issuer }); + const { didDocument: issuerDID } = await this.hsDid.resolve({ did: params.credentialStatus.issuer as string }); const issuerDidDoc: Did = issuerDID as Did; - const issuerDidDocController = issuerDidDoc.controller; + const issuerDidDocController = issuerDidDoc.controller as string[]; const verificationMethodController = params.verificationMethodId.split('#')[0]; if (!issuerDidDocController.includes(verificationMethodController)) { @@ -721,22 +743,20 @@ export default class HypersignVerifiableCredential implements ICredentialMethods const didDocofController = controllerDidDoc as Did; const issuerPublicKeyId = params.verificationMethodId; - const issuerPublicKeyVerMethod: VerificationMethod = didDocofController.verificationMethod.find( - (x) => x.id == issuerPublicKeyId - ) as VerificationMethod; + const issuerPublicKeyVerMethod: VerificationMethod = ( + didDocofController.verificationMethod as VerificationMethod[] + ).find((x) => x.id == issuerPublicKeyId) as VerificationMethod; const proof: CredentialProof = { type: VC.VERIFICATION_METHOD_TYPE, created: params.credentialStatus.issuanceDate, - updated: this._dateNow(), - verificationMethod: issuerPublicKeyVerMethod.id, + verificationMethod: issuerPublicKeyVerMethod.id as string, proofValue, proofPurpose: VC.PROOF_PURPOSE, }; - /// RegisterCRedeRPC - // We use the same RPC (i.e. MsgRegisterCredentialStatus) for register and update of credential status on blockchain - const resp: DeliverTxResponse = await this.credStatusRPC.registerCredentialStatus(credentialStatus, proof); + /// UpdateCredRPC + const resp: DeliverTxResponse = await this.credStatusRPC.updateCredentialStatus(credentialStatus, proof); if (!resp || resp.code != 0) { throw new Error('HID-SSI-SDK:: Error while revoking the credential error = ' + resp.rawLog); @@ -757,7 +777,7 @@ export default class HypersignVerifiableCredential implements ICredentialMethods throw new Error('HID-SSI-SDK:: Error: params.credentialId is required to resolve credential status'); const { credentialId } = params; - let credentialStatus = {} as CredentialStatus; + let credentialStatus = {} as CredentialStatusState; if (!this.credStatusRPC) { throw new Error('HID-SSI-SDK:: Error: HypersignVerifiableCred is not instantiated with Offlinesigner'); } @@ -765,12 +785,15 @@ export default class HypersignVerifiableCredential implements ICredentialMethods if (!credentialStatus) { throw new Error('HID-SSI-SDK:: Error: while checking credential status of credentialID ' + credentialId); } - const claim: Claim = credentialStatus.claim as Claim; - const { currentStatus, statusReason } = claim; - + // const claim: Claim = credentialStatus.claim as Claim; + const { remarks: statusReason } = credentialStatus.credentialStatusDocument as CredentialStatus; + let currentStatus; /// TODO: probably we should also verify the credential HASH by recalculating the hash of the crdential and // matching with credentialHash property. // const { credentialHash } = credentialStatus; + if (!credentialStatus.credentialStatusDocument?.revoked && !credentialStatus.credentialStatusDocument?.suspended) { + currentStatus = VC.CRED_STATUS_TYPES.LIVE; + } if (currentStatus != VC.CRED_STATUS_TYPES.LIVE) { console.log('WARN: Credential status is not LIVE, currentStatus ' + currentStatus); console.log('WARN: Status reason is ' + statusReason); @@ -944,7 +967,7 @@ export default class HypersignVerifiableCredential implements ICredentialMethods if (issuerDID === null || issuerDID === undefined) throw new Error('Could not resolve issuerDid = ' + params.credential.issuer); const credIssuerDidDoc: Did = issuerDID as Did; - const credIssuerController = credIssuerDidDoc.controller; + const credIssuerController = credIssuerDidDoc.controller as string[]; if (!credIssuerController.includes(params.issuerDid)) { throw new Error(params.issuerDid + ' is not a controller of ' + params.credential.issuer); } diff --git a/src/did/IDID.ts b/src/did/IDID.ts index 68d6b93..66bd5cc 100644 --- a/src/did/IDID.ts +++ b/src/did/IDID.ts @@ -4,9 +4,17 @@ * Author: Hypermine Core Team */ -import { Did as IDidProto, Metadata, VerificationMethod, Service, Did, SignInfo } from '../../libs/generated/ssi/did'; +import { + DidDocument as IDidProto, + DidDocumentMetadata as Metadata, + VerificationMethod, + Service, + DidDocument, +} from '../../libs/generated/ssi/did'; +import { DocumentProof as SignInfo } from '../../libs/generated/ssi/proof'; import { ClientSpec } from '../../libs/generated/ssi/clientSpec'; import Web3 from 'web3'; +import { VerificationMethodRelationships, VerificationMethodTypes } from '../../libs/generated/ssi/client/enums'; export interface IPublicKey { '@context': string; @@ -15,22 +23,6 @@ export interface IPublicKey { publicKeyBase58: string; } -export enum IVerificationRelationships { - authentication = 'authentication', - assertionMethod = 'assertionMethod', - keyAgreement = 'keyAgreement', - capabilityInvocation = 'capabilityInvocation', - capabilityDelegation = 'capabilityDelegation', -} - -export enum IKeyType { - Ed25519VerificationKey2020 = 'Ed25519VerificationKey2020', - EcdsaSecp256k1VerificationKey2019 = 'EcdsaSecp256k1VerificationKey2019', - EcdsaSecp256k1RecoveryMethod2020 = 'EcdsaSecp256k1RecoveryMethod2020', - X25519KeyAgreementKey2020 = 'X25519KeyAgreementKey2020', - X25519KeyAgreementKeyEIP5630 = 'X25519KeyAgreementKeyEIP5630', -} - export enum IClientSpec { 'eth-personalSign' = 'eth-personalSign', 'cosmos-ADR036' = 'cosmos-ADR036', @@ -91,20 +83,20 @@ export interface IDID { generate(params: { methodSpecificId?: string; publicKeyMultibase: string; - verificationRelationships: IVerificationRelationships[]; - }): Promise; + verificationRelationships: VerificationMethodRelationships[]; + }): Promise; register(params: { - didDocument: Did; + didDocument: DidDocument; privateKeyMultibase?: string; verificationMethodId?: string; signData?: ISignData[]; - }): Promise<{ didDocument: Did; transactionHash: string }>; + }): Promise<{ didDocument: DidDocument; transactionHash: string }>; resolve(params: { did: string; ed25519verificationkey2020?: boolean }): Promise; update(params: { - didDocument: Did; + didDocument: DidDocument; privateKeyMultibase: string; verificationMethodId: string; versionId: string; @@ -119,7 +111,7 @@ export interface IDID { // didAuth sign(params: { - didDocument: Did; + didDocument: DidDocument; privateKeyMultibase: string; challenge: string; domain: string; @@ -128,7 +120,7 @@ export interface IDID { }): Promise; verify(params: { - didDocument: Did; + didDocument: DidDocument; verificationMethodId: string; challenge: string; domain?: string; @@ -136,13 +128,13 @@ export interface IDID { addVerificationMethod(params: { did?: string; - didDocument?: Did; - type: IKeyType; + didDocument?: DidDocument; + type: VerificationMethodTypes; id?: string; controller?: string; publicKeyMultibase?: string; blockchainAccountId?: string; - }): Promise; + }): Promise; createByClientSpec(params: { methodSpecificId: string; @@ -150,40 +142,40 @@ export interface IDID { address: string; chainId: string; clientSpec: IClientSpec; - verificationRelationships?: IVerificationRelationships[]; - }): Promise; + verificationRelationships?: VerificationMethodRelationships[]; + }): Promise; registerByClientSpec(params: { - didDocument: Did; // Ld document + didDocument: DidDocument; // Ld document signInfos: SignInfo[]; - }): Promise<{ didDocument: Did; transactionHash: string }>; + }): Promise<{ didDocument: DidDocument; transactionHash: string }>; updateByClientSpec(params: { - didDocument: Did; + didDocument: DidDocument; versionId: string; signInfos: SignInfo[]; }): Promise<{ transactionHash: string }>; deactivateByClientSpec(params: { - didDocument: Did; + didDocument: DidDocument; signInfos: SignInfo[]; versionId: string; }): Promise<{ transactionHash: string }>; signAndRegisterByClientSpec(params: { - didDocument: Did; + didDocument: DidDocument; address: string; verificationMethodId: string; web3: Web3 | any; clientSpec: IClientSpec; chainId?: string; // only for [cosmos-ADR036] - }): Promise<{ didDocument: Did; transactionHash: string }>; + }): Promise<{ didDocument: DidDocument; transactionHash: string }>; signByClientSpec(params: { - didDocument: Did; + didDocument: DidDocument; clientSpec: IClientSpec; address: string; web3: Web3 | any; chainId?: string; // only for [cosmos-ADR036] - }): Promise<{ didDocument: Did; signature: string }>; + }): Promise<{ didDocument: DidDocument; signature: string }>; } export interface IDIDResolve { @@ -232,5 +224,5 @@ export interface IDidDocument { export interface ISignData { verificationMethodId: string; privateKeyMultibase: string; - type: IKeyType; + type: VerificationMethodTypes; } diff --git a/src/did/did.ts b/src/did/did.ts index d1c7520..929be2b 100644 --- a/src/did/did.ts +++ b/src/did/did.ts @@ -5,19 +5,19 @@ */ import * as constant from '../constants'; import jsonSigs from 'jsonld-signatures'; -const { AuthenticationProofPurpose } = jsonSigs.purposes; +const { AuthenticationProofPurpose, AssertionProofPurpose } = jsonSigs.purposes; import { DIDRpc } from './didRPC'; import Utils from '../utils'; const ed25519 = require('@stablelib/ed25519'); -import { Did, VerificationMethod, Service, SignInfo } from '../../libs/generated/ssi/did'; +import { DidDocument as Did, VerificationMethod, Service, DidDocument } from '../../libs/generated/ssi/did'; +import { DocumentProof as SignInfo } from '../../libs/generated/ssi/proof'; import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020'; import { Ed25519Signature2020 } from '@digitalbazaar/ed25519-signature-2020'; import Web3 from 'web3'; import DidApiService from '../ssiApi/services/did/did.service'; -import { IDidApiService, IRegister } from '../ssiApi/services/did/IDIDApi'; +import { IDidApiService } from '../ssiApi/services/did/IDIDApi'; import { - IParams, IDID, IDid, IDIDResolve, @@ -25,19 +25,18 @@ import { IController, IDidDocument, ISignedDIDDocument, - IKeyType, IClientSpec, - IVerificationRelationships, ISignData, ISignInfo, } from './IDID'; - +import { VerificationMethodRelationships, VerificationMethodTypes } from '../../libs/generated/ssi/client/enums'; import { OfflineSigner } from '@cosmjs/proto-signing'; import customLoader from '../../libs/w3cache/v1'; import { DeliverTxResponse } from '../did/IDID'; +import { ClientSpecType } from '../../libs/generated/ssi/client_spec'; class DIDDocument implements Did { - context: string[]; + '@context': string[]; id: string; controller: string[]; alsoKnownAs: string[]; @@ -52,13 +51,13 @@ class DIDDocument implements Did { publicKey: string, blockchainAccountId: string, id: string, - keyType: IKeyType, - verificationRelationships?: IVerificationRelationships[] + keyType: VerificationMethodTypes, + verificationRelationships?: VerificationMethodRelationships[] ) { let vm; switch (keyType) { - case IKeyType.Ed25519VerificationKey2020: { - this.context = [constant['DID_' + keyType].DID_BASE_CONTEXT]; + case VerificationMethodTypes.Ed25519VerificationKey2020: { + this['@context'] = [constant['DID_' + keyType].DID_BASE_CONTEXT]; this.id = id; this.controller = [this.id]; this.alsoKnownAs = [this.id]; @@ -67,7 +66,6 @@ class DIDDocument implements Did { type: constant['DID_' + keyType].VERIFICATION_METHOD_TYPE, controller: this.id, publicKeyMultibase: publicKey, - blockchainAccountId: '', }; const verificationMethod: VerificationMethod = vm; @@ -78,7 +76,8 @@ class DIDDocument implements Did { this.capabilityInvocation = []; this.capabilityDelegation = []; verificationRelationships?.forEach((value) => { - this[value] = [verificationMethod.id]; + const vmId = verificationMethod.id as string; + this[value] = [vmId]; }); // TODO: we should take services object in consntructor @@ -86,8 +85,8 @@ class DIDDocument implements Did { break; } - case IKeyType.EcdsaSecp256k1RecoveryMethod2020: { - this.context = [constant['DID_' + keyType].DID_BASE_CONTEXT]; + case VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020: { + this['@context'] = [constant['DID_' + keyType].DID_BASE_CONTEXT]; this.id = id; this.controller = [this.id]; this.alsoKnownAs = [this.id]; @@ -105,15 +104,16 @@ class DIDDocument implements Did { this.capabilityInvocation = []; this.capabilityDelegation = []; verificationRelationships?.forEach((value) => { - this[value] = [verificationMethod.id]; + const vmId = verificationMethod.id as string; + this[value] = [vmId]; }); // TODO: we should take services object in consntructor this.service = []; break; } - case IKeyType.EcdsaSecp256k1VerificationKey2019: { - this.context = [constant['DID_' + keyType].DID_BASE_CONTEXT]; + case VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019: { + this['@context'] = [constant['DID_' + keyType].DID_BASE_CONTEXT]; this.id = id; this.controller = [this.id]; this.alsoKnownAs = []; @@ -132,7 +132,8 @@ class DIDDocument implements Did { this.capabilityInvocation = []; this.capabilityDelegation = []; verificationRelationships?.forEach((value) => { - this[value] = [verificationMethod.id]; + const vmId = verificationMethod.id as string; + this[value] = [vmId]; }); // TODO: we should take services object in consntructor this.service = []; @@ -188,6 +189,10 @@ export default class HypersignDID implements IDID { this.namespace = namespace ? namespace : ''; } + private _getDateTime(): string { + return new Date(new Date().getTime() - 100000).toISOString().slice(0, -5) + 'Z'; + } + private async _sign(params: { didDocString: string; privateKeyMultibase: string }): Promise { const { privateKeyMultibase: privateKeyMultibaseConverted } = Utils.convertEd25519verificationkey2020toStableLibKeysInto({ @@ -202,6 +207,32 @@ export default class HypersignDID implements IDID { return Buffer.from(signed).toString('base64'); } + private async _jsonLdSign(params: { + didDocument: Did; + privateKeyMultibase: string; + verificationMethodId: string; + }): Promise { + const { didDocument, privateKeyMultibase, verificationMethodId } = params; + const publicKeyId = verificationMethodId; + const pubKey = didDocument.verificationMethod?.find((item) => item.id === publicKeyId); + const publicKeyMultibase1 = pubKey?.publicKeyMultibase; + if (didDocument['@context'] && !didDocument['@context'].includes(constant.VC.CREDENTAIL_SECURITY_SUITE)) { + didDocument['@context']?.push(constant.VC.CREDENTAIL_SECURITY_SUITE); + } + const keyPair = await Ed25519VerificationKey2020.from({ + id: publicKeyId, + privateKeyMultibase: privateKeyMultibase, + publicKeyMultibase: publicKeyMultibase1, + }); + const suite = new Ed25519Signature2020({ key: keyPair }); + const signedDidDocument = (await jsonSigs.sign(didDocument, { + suite, + purpose: new AssertionProofPurpose(), + documentLoader: customLoader, + })) as ISignedDIDDocument; + return signedDidDocument.proof; + } + private _getId = (methodSpecificId: string) => { if (methodSpecificId && methodSpecificId.length < 32) { throw new Error('HID-SSI-SDK:: Error: methodSpecificId should be of minimum size 32'); @@ -215,13 +246,13 @@ export default class HypersignDID implements IDID { }; private _filterVerificationRelationships( - verificationRelationships: IVerificationRelationships[] - ): IVerificationRelationships[] { - let vR: IVerificationRelationships[] = [ - IVerificationRelationships.assertionMethod, - IVerificationRelationships.authentication, - IVerificationRelationships.capabilityDelegation, - IVerificationRelationships.capabilityInvocation, + verificationRelationships: VerificationMethodRelationships[] + ): VerificationMethodRelationships[] { + let vR: VerificationMethodRelationships[] = [ + VerificationMethodRelationships.assertionMethod, + VerificationMethodRelationships.authentication, + VerificationMethodRelationships.capabilityDelegation, + VerificationMethodRelationships.capabilityInvocation, ]; if (verificationRelationships && verificationRelationships.length > 0) { const set1 = new Set(vR); @@ -303,11 +334,11 @@ export default class HypersignDID implements IDID { public async generate(params: { methodSpecificId?: string; publicKeyMultibase: string; - verificationRelationships?: IVerificationRelationships[]; + verificationRelationships?: VerificationMethodRelationships[]; }): Promise { - let verificationRelationships: IVerificationRelationships[] = []; + let verificationRelationships: VerificationMethodRelationships[] = []; if (params.verificationRelationships && params.verificationRelationships.length > 0) { - if (params.verificationRelationships.includes(IVerificationRelationships.keyAgreement)) { + if (params.verificationRelationships.includes(VerificationMethodRelationships.keyAgreement)) { throw new Error('HID-SSI-SDK:: Error: keyAgreement is not allowed in verificationRelationships'); } verificationRelationships = this._filterVerificationRelationships(params.verificationRelationships); @@ -317,10 +348,7 @@ export default class HypersignDID implements IDID { if (!params.publicKeyMultibase) { throw new Error('HID-SSI-SDK:: Error: params.publicKeyMultibase is required to generate new did didoc'); } - const { publicKeyMultibase: publicKeyMultibase1 } = Utils.convertEd25519verificationkey2020toStableLibKeysInto({ - publicKey: params.publicKeyMultibase, - }); - + const publicKeyMultibase1 = params.publicKeyMultibase; const methodSpecificId = publicKeyMultibase1; let didId; if (params.methodSpecificId) { @@ -333,7 +361,7 @@ export default class HypersignDID implements IDID { publicKeyMultibase1, '', didId, - IKeyType.Ed25519VerificationKey2020, + VerificationMethodTypes.Ed25519VerificationKey2020, verificationRelationships ) as IDid; return Utils.jsonToLdConvertor({ ...newDid }); @@ -364,8 +392,7 @@ export default class HypersignDID implements IDID { ); } const { didDocument } = params; - const didDocStringJson = Utils.ldToJsonConvertor(didDocument); - const didDoc: Did = didDocStringJson as Did; + const didDoc: Did = didDocument as Did; const signInfos: Array = []; if (!params.signData) { if (!params.privateKeyMultibase) { @@ -375,14 +402,29 @@ export default class HypersignDID implements IDID { throw new Error('HID-SSI-SDK:: Error: params.verificationMethodId is required to register a did'); } const { privateKeyMultibase, verificationMethodId } = params; - const signature: string = await this._sign({ - didDocString: JSON.stringify(didDocStringJson), - privateKeyMultibase, - }); + let signature; + let createdAt; + if (!didDocument['@context']) { + signature = await this._sign({ + didDocString: JSON.stringify(didDocument), + privateKeyMultibase, + }); + } else { + const proof = await this._jsonLdSign({ + didDocument: didDocument, + privateKeyMultibase, + verificationMethodId, + }); + signature = proof.proofValue; + createdAt = proof.created; + } + signInfos.push({ - signature, - verification_method_id: verificationMethodId, - clientSpec: undefined, + type: constant['DID_Ed25519VerificationKey2020'].SIGNATURE_TYPE, + created: createdAt ?? this._getDateTime(), + verificationMethod: verificationMethodId, + proofPurpose: VerificationMethodRelationships.assertionMethod, + proofValue: signature, }); } else { if (params.signData.length < 1) { @@ -403,16 +445,34 @@ export default class HypersignDID implements IDID { throw new Error(`HID-SSI-SDK:: Error: params.signData[${i}].type is required to register a did`); } const { type, privateKeyMultibase, verificationMethodId } = params.signData[i]; - if (type !== IKeyType.X25519KeyAgreementKey2020 && type !== IKeyType.X25519KeyAgreementKeyEIP5630) { - const signature: string = await this._sign({ - didDocString: JSON.stringify(didDocStringJson), - privateKeyMultibase, - }); + let createdAt; + if ( + type !== VerificationMethodTypes.X25519KeyAgreementKey2020 && + type !== VerificationMethodTypes.X25519KeyAgreementKeyEIP5630 + ) { + let signature: string; + if (!didDocument['@context']) { + signature = await this._sign({ + didDocString: JSON.stringify(didDocument), + privateKeyMultibase, + }); + } else { + const proof: SignInfo = await this._jsonLdSign({ + didDocument: didDocument, + privateKeyMultibase, + verificationMethodId, + }); + signature = proof.proofValue as string; + createdAt = proof.created; + } signInfos.push({ - signature, - verification_method_id: verificationMethodId, - clientSpec: undefined, + type: constant['DID_Ed25519VerificationKey2020'].SIGNATURE_TYPE, + created: createdAt ?? this._getDateTime(), + verificationMethod: verificationMethodId, + proofPurpose: VerificationMethodRelationships.assertionMethod, + proofValue: signature, }); + delete didDocument['proof']; } } } @@ -447,9 +507,8 @@ export default class HypersignDID implements IDID { privateKeyMultibase, }); signInfos.push({ - signature, - verification_method_id: verificationMethodId, - clientSpec: undefined, + proofValue: signature, + verificationMethod: verificationMethodId, }); return signInfos; } @@ -506,7 +565,6 @@ export default class HypersignDID implements IDID { versionId: string; }): Promise<{ transactionHash: string }> { const response = {} as { transactionHash: string }; - if (!params.didDocument) { throw new Error('HID-SSI-SDK:: Error: params.didDocument is required to update a did'); } @@ -528,23 +586,27 @@ export default class HypersignDID implements IDID { } const { didDocument, privateKeyMultibase, verificationMethodId, versionId } = params; - const didDocStringJson = Utils.ldToJsonConvertor(didDocument); - const signature = await this._sign({ didDocString: JSON.stringify(didDocStringJson), privateKeyMultibase }); - const didDoc: Did = didDocStringJson as Did; + const proof = await this._jsonLdSign({ + didDocument, + privateKeyMultibase, + verificationMethodId, + }); const signInfos: Array = [ { - signature, - verification_method_id: verificationMethodId, - clientSpec: undefined, + type: constant['DID_Ed25519VerificationKey2020'].SIGNATURE_TYPE, + created: proof.created ?? this._getDateTime(), + verificationMethod: verificationMethodId, + proofPurpose: VerificationMethodRelationships.assertionMethod, + proofValue: proof.proofValue, }, ]; if (this.didrpc) { - const result: DeliverTxResponse = await this.didrpc.updateDID(didDoc, signInfos, versionId); + const result: DeliverTxResponse = await this.didrpc.updateDID(didDocument, signInfos, versionId); response.transactionHash = result.transactionHash; } else if (this.didAPIService) { const newSignInfos = signInfos as Array; const result = await this.didAPIService.updateDid({ - didDocument: didDoc as Did, + didDocument: didDocument as Did, signInfos: newSignInfos, deactivate: false, }); @@ -569,7 +631,6 @@ export default class HypersignDID implements IDID { versionId: string; }): Promise<{ transactionHash: string }> { const response = {} as { transactionHash: string }; - if (!params.didDocument) { throw new Error('HID-SSI-SDK:: Error: params.didDocument is required to deactivate a did'); } @@ -591,18 +652,23 @@ export default class HypersignDID implements IDID { } const { didDocument, privateKeyMultibase, verificationMethodId, versionId } = params; - const didDocStringJson = Utils.ldToJsonConvertor(didDocument); - const signature = await this._sign({ didDocString: JSON.stringify(didDocStringJson), privateKeyMultibase }); - const didDoc: Did = didDocStringJson as Did; + + const proof = await this._jsonLdSign({ + didDocument, + privateKeyMultibase, + verificationMethodId, + }); const signInfos: Array = [ { - signature, - verification_method_id: verificationMethodId, - clientSpec: undefined, + type: constant['DID_Ed25519VerificationKey2020'].SIGNATURE_TYPE, + created: proof.created ?? this._getDateTime(), + verificationMethod: verificationMethodId, + proofPurpose: VerificationMethodRelationships.assertionMethod, + proofValue: proof.proofValue, }, ]; if (this.didrpc) { - const result: DeliverTxResponse = await this.didrpc.deactivateDID(didDoc.id, signInfos, versionId); + const result: DeliverTxResponse = await this.didrpc.deactivateDID(didDocument.id as string, signInfos, versionId); response.transactionHash = result.transactionHash; } else if (this.didAPIService) { const newSignInfos = signInfos as Array; @@ -666,10 +732,8 @@ export default class HypersignDID implements IDID { if (!pubkey) { throw new Error('HID-SSI-SDK:: Error: Incorrect verification method id'); } - const { publicKeyMultibase: publicKeyMultibase1 } = Utils.convertedStableLibKeysIntoEd25519verificationkey2020({ - publicKey: pubkey.publicKeyMultibase, - }); + const publicKeyMultibase1 = pubkey.publicKeyMultibase; const keyPair = await Ed25519VerificationKey2020.from({ id: publicKeyId, privateKeyMultibase, @@ -680,10 +744,10 @@ export default class HypersignDID implements IDID { verificationMethod: publicKeyId, key: keyPair, }); - const didDocumentLd = Utils.jsonToLdConvertor(resolveddoc.didDocument); - didDocumentLd['@context'].push(constant.VC.CREDENTAIL_SECURITY_SUITE); - // didDocumentLd['@context'].push(constant.VC.CREDENTAIL_ECDSA_SECURITY_SUITE) - + const didDocumentLd = resolveddoc.didDocument; + if (didDocumentLd['@context'] && !didDocumentLd['@context'].includes(constant.VC.CREDENTAIL_SECURITY_SUITE)) { + didDocumentLd['@context']?.push(constant.VC.CREDENTAIL_SECURITY_SUITE); + } const signedDidDocument = (await jsonSigs.sign(didDocumentLd, { suite, purpose: new AuthenticationProofPurpose({ @@ -732,7 +796,7 @@ export default class HypersignDID implements IDID { const didDoc = didDocument as Did; const publicKeyId = verificationMethodId; - const pubkey = didDoc.verificationMethod.find((item) => item.id === publicKeyId); + const pubkey = didDoc.verificationMethod?.find((item) => item.id === publicKeyId); if (!pubkey) { throw new Error( @@ -742,10 +806,7 @@ export default class HypersignDID implements IDID { ); } - const { publicKeyMultibase: publicKeyMultibase1 } = Utils.convertedStableLibKeysIntoEd25519verificationkey2020({ - publicKey: pubkey.publicKeyMultibase, - }); - + const publicKeyMultibase1 = pubkey.publicKeyMultibase; const keyPair = await Ed25519VerificationKey2020.from({ id: publicKeyId, @@ -760,7 +821,7 @@ export default class HypersignDID implements IDID { const controller: IController = { '@context': constant.DID.CONTROLLER_CONTEXT, id: publicKeyId, - authentication: didDoc.authentication, + authentication: didDoc.authentication as string[], }; const purpose = new AuthenticationProofPurpose({ @@ -799,7 +860,7 @@ export default class HypersignDID implements IDID { address: string; chainId: string; clientSpec: IClientSpec; - verificationRelationships?: IVerificationRelationships[]; + verificationRelationships?: VerificationMethodRelationships[]; }): Promise { if (this['window'] === 'undefined') { console.log('HID-SSI-SDK:: Warning: Running in non browser mode'); @@ -822,9 +883,9 @@ export default class HypersignDID implements IDID { throw new Error('HID-SSI-SDK:: Error: params.clientSpec is invalid'); } let didDoc; - let verificationRelationships: IVerificationRelationships[] = []; + let verificationRelationships: VerificationMethodRelationships[] = []; if (params.verificationRelationships && params.verificationRelationships.length > 0) { - if (params.verificationRelationships.includes(IVerificationRelationships.keyAgreement)) { + if (params.verificationRelationships.includes(VerificationMethodRelationships.keyAgreement)) { throw new Error('HID-SSI-SDK:: Error: keyAgreement is not allowed in verificationRelationships'); } verificationRelationships = this._filterVerificationRelationships(params.verificationRelationships); @@ -841,7 +902,7 @@ export default class HypersignDID implements IDID { '', blockChainAccountId, didId, - IKeyType.EcdsaSecp256k1RecoveryMethod2020, + VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020, verificationRelationships ); didDoc = Utils.jsonToLdConvertor({ ...newDid }); @@ -852,13 +913,13 @@ export default class HypersignDID implements IDID { if (!params.publicKey) { throw new Error( 'HID-SSI-SDK:: Error: params.publicKey is required to create didoc for ' + - IKeyType.EcdsaSecp256k1VerificationKey2019 + VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019 ); } if (!this._isValidMultibaseBase58String(params.publicKey)) { throw new Error( 'HID-SSI-SDK:: Error: params.publicKey mustbe multibase encoded base58 string for ' + - IKeyType.EcdsaSecp256k1VerificationKey2019 + VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019 ); } @@ -869,7 +930,7 @@ export default class HypersignDID implements IDID { multibasePublicKey, blockChainAccountId, didId, - IKeyType.EcdsaSecp256k1VerificationKey2019 + VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019 ); didDoc = Utils.jsonToLdConvertor({ ...newDid }); @@ -919,27 +980,27 @@ export default class HypersignDID implements IDID { throw new Error('HID-SSI-SDK:: Error: params.signInfos must be a non empty array'); } for (const i in params.signInfos) { - if (!params.signInfos[i].verification_method_id) { + if (!params.signInfos[i]['verification_method_id']) { throw new Error( `HID-SSI-SDK:: Error: params.signInfos[${i}].verification_method_id is required to register a did` ); } - const clientSpec = params.signInfos[i].clientSpec; + const clientSpec = params.signInfos[i]['clientSpec']; if (clientSpec && clientSpec.type && !(clientSpec.type in IClientSpec)) { throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${0}].clientSpec is invalid`); } - if (params.signInfos[i].clientSpec?.type === IClientSpec['cosmos-ADR036']) { + if (params.signInfos[i]['clientSpec']?.type === IClientSpec['cosmos-ADR036']) { if ( - params.signInfos[i].clientSpec?.adr036SignerAddress === '' || - params.signInfos[i].clientSpec?.adr036SignerAddress === undefined + params.signInfos[i]['clientSpec']?.adr036SignerAddress === '' || + params.signInfos[i]['clientSpec']?.adr036SignerAddress === undefined ) { throw new Error( - `HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to register a did, when clientSpec type is${params.signInfos[i].clientSpec?.type} ` + `HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to register a did, when clientSpec type is${params.signInfos[i]['clientSpec']?.type} ` ); } } - if (!params.signInfos[i].signature) { + if (!params.signInfos[i]['signature']) { throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].signature is required to register a did`); } } @@ -994,29 +1055,29 @@ export default class HypersignDID implements IDID { throw new Error('HID-SSI-SDK:: Error: params.signInfos must be a non empty array'); } for (const i in params.signInfos) { - if (!params.signInfos[i].verification_method_id) { + if (!params.signInfos[i]['verification_method_id']) { throw new Error( `HID-SSI-SDK:: Error: params.signInfos[${i}].verification_method_id is required to register a did` ); } - const clientSpec = params.signInfos[i].clientSpec; + const clientSpec = params.signInfos[i]['clientSpec']; if (clientSpec && clientSpec.type && !(clientSpec.type in IClientSpec)) { throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${0}].clientSpec is invalid`); } - if (params.signInfos[i].clientSpec?.type === IClientSpec['cosmos-ADR036']) { + if (params.signInfos[i]['clientSpec']?.type === IClientSpec['cosmos-ADR036']) { if ( - params.signInfos[i].clientSpec?.adr036SignerAddress === '' || - params.signInfos[i].clientSpec?.adr036SignerAddress === undefined + params.signInfos[i]['clientSpec']?.adr036SignerAddress === '' || + params.signInfos[i]['clientSpec']?.adr036SignerAddress === undefined ) { throw new Error( - `HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to register a did, when clientSpec type is${params.signInfos[i].clientSpec?.type} ` + `HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to register a did, when clientSpec type is${params.signInfos[i]['clientSpec']?.type} ` ); } } - if (!params.signInfos[i].signature) { + if (!params.signInfos[i]['signature']) { throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].signature is required to register a did`); } } @@ -1072,28 +1133,28 @@ export default class HypersignDID implements IDID { } for (const i in params.signInfos) { - if (!params.signInfos[i].verification_method_id) { + if (!params.signInfos[i]['verification_method_id']) { throw new Error( `HID-SSI-SDK:: Error: params.signInfos[${i}].verification_method_id is required to deactivate a did` ); } - const clientSpec = params.signInfos[i].clientSpec; + const clientSpec = params.signInfos[i]['clientSpec']; if (clientSpec && clientSpec.type && !(clientSpec.type in IClientSpec)) { throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${0}].clientSpec is invalid`); } - if (params.signInfos[i].clientSpec?.type === IClientSpec['cosmos-ADR036']) { + if (params.signInfos[i]['clientSpec']?.type === IClientSpec['cosmos-ADR036']) { if ( - params.signInfos[i].clientSpec?.adr036SignerAddress === '' || - params.signInfos[i].clientSpec?.adr036SignerAddress === undefined + params.signInfos[i]['clientSpec']?.adr036SignerAddress === '' || + params.signInfos[i]['clientSpec']?.adr036SignerAddress === undefined ) { throw new Error( - `HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to deactivate a did, when clientSpec type is${params.signInfos[i].clientSpec?.type} ` + `HID-SSI-SDK:: Error: params.signInfos[${i}].adr036SignerAddress is required to deactivate a did, when clientSpec type is${params.signInfos[i]['clientSpec']?.type} ` ); } } - if (!params.signInfos[i].signature) { + if (!params.signInfos[i]['signature']) { throw new Error(`HID-SSI-SDK:: Error: params.signInfos[${i}].signature is required to deactivate a did`); } } @@ -1104,7 +1165,7 @@ export default class HypersignDID implements IDID { const { didDocument, signInfos, versionId } = params; const didDoc: Did = didDocument as Did; if (this.didrpc) { - const result: DeliverTxResponse = await this.didrpc.deactivateDID(didDoc.id, signInfos, versionId); + const result: DeliverTxResponse = await this.didrpc.deactivateDID(didDoc.id as string, signInfos, versionId); response.transactionHash = result.transactionHash; } else if (this.didAPIService) { const newSignInfos = signInfos as Array; @@ -1172,12 +1233,16 @@ export default class HypersignDID implements IDID { const signInfos: Array = [ { - signature, - verification_method_id: params.verificationMethodId, - clientSpec: { - type: params.clientSpec, - adr036SignerAddress: params.clientSpec === IClientSpec['cosmos-ADR036'] ? params.address : '', - }, + proofValue: signature, + verificationMethod: params.verificationMethodId, + // clientSpec: { + // type: params.clientSpec, + // adr036SignerAddress: params.clientSpec === IClientSpec['cosmos-ADR036'] ? params.address : '', + // }, + clientSpecType: + params.clientSpec === IClientSpec['cosmos-ADR036'] + ? ClientSpecType.CLIENT_SPEC_TYPE_COSMOS_ADR036 + : ClientSpecType.CLIENT_SPEC_TYPE_ETH_PERSONAL_SIGN, }, ]; return await this.registerByClientSpec({ @@ -1245,7 +1310,7 @@ export default class HypersignDID implements IDID { 'HID-SSI-SDK:: Error: params.chainId is required to sign for clientSpec ' + IClientSpec['cosmos-ADR036'] + ' and keyType ' + - IKeyType.EcdsaSecp256k1VerificationKey2019 + VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019 ); } const didDocStringJson = Utils.ldToJsonConvertor(params.didDocument); @@ -1281,7 +1346,7 @@ export default class HypersignDID implements IDID { public async addVerificationMethod(params: { did?: string; didDocument?: Did; - type: IKeyType; + type: VerificationMethodTypes; id?: string; // verificationMethodId controller?: string; publicKeyMultibase?: string; @@ -1296,7 +1361,7 @@ export default class HypersignDID implements IDID { throw new Error('HID-SSI-SDK:: Error: params.type is required to addVerificationMethod'); } const { type } = params; - if (!(type in IKeyType)) { + if (!(type in VerificationMethodTypes)) { throw new Error('HID-SSI-SDK:: Error: params.type is invalid'); } try { @@ -1322,16 +1387,16 @@ export default class HypersignDID implements IDID { throw new Error(`HID-SSI-SDK:: Error: could not resolve did ${params.did}`); } if ( - type === IKeyType.EcdsaSecp256k1RecoveryMethod2020 && + type === VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020 && (!params.blockchainAccountId || params.blockchainAccountId.trim() === '') ) { throw new Error(`HID-SSI-SDK:: Error: params.blockchainAccountId is required for keyType ${params.type}`); } - if (type === IKeyType.EcdsaSecp256k1RecoveryMethod2020 && (!params.id || params.id.trim() === '')) { + if (type === VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020 && (!params.id || params.id.trim() === '')) { throw new Error(`HID-SSI-SDK:: Error: params.id is required for keyType ${params.type}`); } if ( - type === IKeyType.EcdsaSecp256k1VerificationKey2019 && + type === VerificationMethodTypes.EcdsaSecp256k1VerificationKey2019 && (!params.blockchainAccountId || params.blockchainAccountId.trim() === '' || !params.publicKeyMultibase || @@ -1343,16 +1408,15 @@ export default class HypersignDID implements IDID { } if ( - (type === IKeyType.Ed25519VerificationKey2020 || - type === IKeyType.X25519KeyAgreementKey2020 || - type === IKeyType.X25519KeyAgreementKeyEIP5630) && + (type === VerificationMethodTypes.Ed25519VerificationKey2020 || + type === VerificationMethodTypes.X25519KeyAgreementKey2020 || + type === VerificationMethodTypes.X25519KeyAgreementKeyEIP5630) && !params.publicKeyMultibase ) { throw new Error('HID-SSI-SDK:: Error: params.publicKeyMultibase is required to addVerificationMethod'); } const verificationMethod = {} as VerificationMethod; - let { didDocument } = resolvedDidDoc; - didDocument = Utils.ldToJsonConvertor(didDocument); + const { didDocument } = resolvedDidDoc; if (params.id) { const checkIfVmIdExists = didDocument.verificationMethod.some((vm) => vm.id === params.id); @@ -1365,21 +1429,16 @@ export default class HypersignDID implements IDID { verificationMethod['id'] = params?.id ?? `${didDocument.id}#key-${VMLength + 1}`; verificationMethod['type'] = type; verificationMethod['controller'] = didDocument.id; - if (type !== IKeyType.EcdsaSecp256k1RecoveryMethod2020) { - if (type === IKeyType.Ed25519VerificationKey2020) { - const { publicKeyMultibase: publicKeyMultibase1 } = Utils.convertEd25519verificationkey2020toStableLibKeysInto({ - publicKey: params.publicKeyMultibase, - }); - verificationMethod['publicKeyMultibase'] = publicKeyMultibase1; - } else { - verificationMethod['publicKeyMultibase'] = params?.publicKeyMultibase ?? ''; - } + if (type !== VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020) { + verificationMethod['publicKeyMultibase'] = params?.publicKeyMultibase ?? ''; + } + if (type !== VerificationMethodTypes.Ed25519VerificationKey2020) { + verificationMethod['blockchainAccountId'] = params?.blockchainAccountId ?? ''; } - verificationMethod['blockchainAccountId'] = params?.blockchainAccountId ?? ''; didDocument.verificationMethod.push(verificationMethod); if ( - verificationMethod['type'] === IKeyType.X25519KeyAgreementKey2020 || - verificationMethod['type'] === IKeyType.X25519KeyAgreementKeyEIP5630 + verificationMethod['type'] === VerificationMethodTypes.X25519KeyAgreementKey2020 || + verificationMethod['type'] === VerificationMethodTypes.X25519KeyAgreementKeyEIP5630 ) { didDocument.keyAgreement.push(verificationMethod['id']); } else { @@ -1388,16 +1447,17 @@ export default class HypersignDID implements IDID { didDocument.capabilityDelegation.push(verificationMethod['id']); didDocument.capabilityInvocation.push(verificationMethod['id']); } - if (verificationMethod['type'] === IKeyType.X25519KeyAgreementKey2020) { - const newContext = constant['DID_' + IKeyType.Ed25519VerificationKey2020].DID_KEYAGREEMENT_CONTEXT; - if (!didDocument['context'].includes(newContext)) { - didDocument['context'].push(newContext); + if (verificationMethod['type'] === VerificationMethodTypes.X25519KeyAgreementKey2020) { + const newContext = constant['DID_' + VerificationMethodTypes.Ed25519VerificationKey2020].DID_KEYAGREEMENT_CONTEXT; + if (!didDocument['@context'].includes(newContext)) { + didDocument['@context'].push(newContext); } } - if (verificationMethod['type'] === IKeyType.X25519KeyAgreementKeyEIP5630) { - const newContext = constant['DID_' + IKeyType.EcdsaSecp256k1RecoveryMethod2020].DID_KEYAGREEMENT_CONTEXT; - if (!didDocument['context'].includes(newContext)) { - didDocument['context'].push(newContext); + if (verificationMethod['type'] === VerificationMethodTypes.X25519KeyAgreementKeyEIP5630) { + const newContext = + constant['DID_' + VerificationMethodTypes.EcdsaSecp256k1RecoveryMethod2020].DID_KEYAGREEMENT_CONTEXT; + if (!didDocument['@context'].includes(newContext)) { + didDocument['@context'].push(newContext); } } return didDocument; diff --git a/src/did/didRPC.ts b/src/did/didRPC.ts index 469ba67..0181eb8 100644 --- a/src/did/didRPC.ts +++ b/src/did/didRPC.ts @@ -6,12 +6,14 @@ import { HIDRpcEnums, HID_COSMOS_MODULE, HYPERSIGN_NETWORK_DID_PATH } from '../constants'; import * as generatedProto from '../../libs/generated/ssi/tx'; -import { Did as IDidProto, SignInfo } from '../../libs/generated/ssi/did'; +import { DidDocument as IDidProto } from '../../libs/generated/ssi/did'; +import { DocumentProof as SignInfo } from '../../libs/generated/ssi/proof'; + import { SigningStargateClient } from '@cosmjs/stargate'; import axios from 'axios'; import { HIDClient } from '../hid/client'; -import { IClientSpec, IDIDResolve, IDIDRpc, IKeyType, DeliverTxResponse } from './IDID'; +import { IDIDResolve, IDIDRpc, DeliverTxResponse } from './IDID'; import { OfflineSigner } from '@cosmjs/proto-signing'; export class DIDRpc implements IDIDRpc { @@ -46,15 +48,15 @@ export class DIDRpc implements IDIDRpc { if (!this.hidClient) { throw new Error('HID-SSI-SDK:: Error: DIDRpc class is not initialise with offlinesigner'); } - - const typeUrl = `${HID_COSMOS_MODULE}.${HIDRpcEnums.MsgCreateDID}`; + delete didDoc['proof']; + const typeUrl = `${HID_COSMOS_MODULE}.${HIDRpcEnums.MsgRegisterDID}`; const txMessage = { typeUrl, // Same as above - value: generatedProto[HIDRpcEnums.MsgCreateDID].fromPartial({ - didDocString: didDoc, - signatures: signInfos, - creator: HIDClient.getHidWalletAddress(), + value: generatedProto[HIDRpcEnums.MsgRegisterDID].fromPartial({ + didDocument: didDoc, + didDocumentProofs: signInfos, + txAuthor: HIDClient.getHidWalletAddress(), }), }; const fee = 'auto'; @@ -73,10 +75,10 @@ export class DIDRpc implements IDIDRpc { const txMessage = { typeUrl, // Same as above value: generatedProto[HIDRpcEnums.MsgUpdateDID].fromPartial({ - didDocString: didDoc, - signatures: signInfos, - creator: HIDClient.getHidWalletAddress(), - version_id: versionId, + didDocument: didDoc, + didDocumentProofs: signInfos, + txAuthor: HIDClient.getHidWalletAddress(), + versionId: versionId, }), }; @@ -98,10 +100,10 @@ export class DIDRpc implements IDIDRpc { const txMessage = { typeUrl, // Same as above value: generatedProto[HIDRpcEnums.MsgDeactivateDID].fromPartial({ - didId: did, - signatures: signInfos, - creator: HIDClient.getHidWalletAddress(), - version_id: versionId, + didDocumentId: did, + didDocumentProofs: signInfos, + txAuthor: HIDClient.getHidWalletAddress(), + versionId: versionId, }), }; diff --git a/src/index.ts b/src/index.ts index 3401c29..89ceebd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,10 +3,12 @@ import HypersignVerifiableCredential from './credential/vc'; import HypersignVerifiablePresentation from './presentation/vp'; import HypersignSchema from './schema/schema'; import { OfflineSigner } from '@cosmjs/proto-signing'; -import { IClientSpec, IKeyType, ISignInfo, IVerificationRelationships } from './did/IDID'; -import { Did } from '../libs/generated/ssi/did'; +import { IClientSpec, ISignInfo } from './did/IDID'; +import { VerificationMethodTypes as IKeyType } from '../libs/generated/ssi/client/enums' +import { VerificationMethodRelationships as IVerificationRelationships } from '../libs/generated/ssi/client/enums' +import { DidDocument as Did } from '../libs/generated/ssi/did'; import { IVerifiableCredential } from './credential/ICredential'; -import { Schema } from '../libs/generated/ssi/schema'; +import { CredentialSchemaDocument as Schema } from '../libs/generated/ssi/credential_schema'; import { IVerifiablePresentation } from './presentation/IPresentation'; class HypersignSSISdk { diff --git a/src/presentation/vp.ts b/src/presentation/vp.ts index f47fbd3..e93839d 100644 --- a/src/presentation/vp.ts +++ b/src/presentation/vp.ts @@ -8,7 +8,7 @@ import { JCS } from 'jcs'; import vc from 'vc-js'; import jsonSigs from 'jsonld-signatures'; import HypersignDID from '../did/did'; -import { Did, VerificationMethod } from '../../libs/generated/ssi/did'; +import { DidDocument as Did, VerificationMethod } from '../../libs/generated/ssi/did'; import { Ed25519Signature2020 } from '@digitalbazaar/ed25519-signature-2020'; import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020'; import Utils from '../utils'; @@ -146,12 +146,6 @@ export default class HypersignVerifiablePresentation implements IPresentationMet (x) => x.id == publicKeyId ) as VerificationMethod; - const convertedKeyPair = Utils.convertedStableLibKeysIntoEd25519verificationkey2020({ - publicKey: publicKeyVerMethod.publicKeyMultibase, - }); - - publicKeyVerMethod['publicKeyMultibase'] = convertedKeyPair.publicKeyMultibase; - const keyPair = await Ed25519VerificationKey2020.from({ privateKeyMultibase: params.privateKeyMultibase, ...publicKeyVerMethod, @@ -243,18 +237,10 @@ export default class HypersignVerifiablePresentation implements IPresentationMet const holderDidDoc: Did = holderDID as Did; const holderPublicKeyId = params.holderVerificationMethodId; - const holderPublicKeyVerMethod: VerificationMethod = holderDidDoc.verificationMethod.find( + const holderPublicKeyVerMethod: VerificationMethod = (holderDidDoc.verificationMethod as VerificationMethod[]).find( (x) => x.id == holderPublicKeyId ) as VerificationMethod; - // Connvert the 45 byte pub key of holder into 48 byte - const { publicKeyMultibase: holderPublicKeyMultibase } = Utils.convertedStableLibKeysIntoEd25519verificationkey2020( - { - publicKey: holderPublicKeyVerMethod.publicKeyMultibase, - } - ); - holderPublicKeyVerMethod.publicKeyMultibase = holderPublicKeyMultibase; - const holderController = { '@context': DID.CONTROLLER_CONTEXT, id: holderDidDoc.id, @@ -285,7 +271,7 @@ export default class HypersignVerifiablePresentation implements IPresentationMet } const issuerDidDoc: Did = issuerDID as Did; - const issuerDidDocController = issuerDidDoc.controller; + const issuerDidDocController = issuerDidDoc.controller as string[]; const issuerDidDocControllerVerificationMethod = params.issuerVerificationMethodId.split('#')[0]; if (!issuerDidDocController.includes(issuerDidDocControllerVerificationMethod)) { @@ -294,7 +280,7 @@ export default class HypersignVerifiablePresentation implements IPresentationMet const issuerPublicKeyId = params.issuerVerificationMethodId; - let issuerPublicKeyVerMethod: VerificationMethod = issuerDidDoc.verificationMethod.find( + let issuerPublicKeyVerMethod: VerificationMethod = (issuerDidDoc.verificationMethod as VerificationMethod[]).find( (x) => x.id == issuerPublicKeyId ) as VerificationMethod; @@ -303,17 +289,10 @@ export default class HypersignVerifiablePresentation implements IPresentationMet did: issuerDidDocControllerVerificationMethod, }); const controllerDidDoc: Did = controllerDidDocT as Did; - issuerPublicKeyVerMethod = controllerDidDoc.verificationMethod.find( + issuerPublicKeyVerMethod = (controllerDidDoc.verificationMethod as VerificationMethod[]).find( (x) => x.id == issuerPublicKeyId ) as VerificationMethod; } - // Connvert the 45 byte pub key of issuer into 48 byte - const { publicKeyMultibase: issuerPublicKeyMultibase } = Utils.convertedStableLibKeysIntoEd25519verificationkey2020( - { - publicKey: issuerPublicKeyVerMethod.publicKeyMultibase, - } - ); - issuerPublicKeyVerMethod.publicKeyMultibase = issuerPublicKeyMultibase; const issuerController = { '@context': DID.CONTROLLER_CONTEXT, @@ -502,18 +481,10 @@ export default class HypersignVerifiablePresentation implements IPresentationMet const publicKeyId = params.issuerVerificationMethodId; const issuerDidDoc: Did = issuerDID as Did; - const publicKeyVerMethod: VerificationMethod = issuerDidDoc.verificationMethod.find( + const publicKeyVerMethod: VerificationMethod = (issuerDidDoc.verificationMethod as VerificationMethod[]).find( (x) => x.id == publicKeyId ) as VerificationMethod; - // TODO: Get rid of this hack later. - // Convert 45 byte publick key into 48 - const { publicKeyMultibase } = Utils.convertedStableLibKeysIntoEd25519verificationkey2020({ - publicKey: publicKeyVerMethod.publicKeyMultibase, - }); - - publicKeyVerMethod.publicKeyMultibase = publicKeyMultibase; - const assertionController = { '@context': ['DID.CONTROLLER_CONTEXT'], id: issuerDidDoc.id, diff --git a/src/schema/ISchema.ts b/src/schema/ISchema.ts index b5cff0e..9c6eec1 100644 --- a/src/schema/ISchema.ts +++ b/src/schema/ISchema.ts @@ -4,7 +4,11 @@ * Author: Hypermine Core Team */ -import { Schema as ISchemaProto, Schema, SchemaDocument } from '../../libs/generated/ssi/schema'; +import { + CredentialSchemaState as Schema, + CredentialSchemaDocument as SchemaDocument, +} from '../../libs/generated/ssi/credential_schema'; +import { DocumentProof } from '../../libs/generated/ssi/proof'; export interface ISchemaFields { type: string; format?: string; @@ -21,9 +25,17 @@ export interface ISchemaMethods { additionalProperties: boolean; }): Promise; - sign(params: { privateKeyMultibase: string; schema: SchemaDocument; verificationMethodId: string }): Promise; + sign(params: { + privateKeyMultibase: string; + schema: SchemaDocument; + verificationMethodId: string; + }): Promise; register(params: { schema: Schema }): Promise<{ transactionHash: string }>; - resolve(params: { schemaId: string }): Promise; + resolve(params: { schemaId: string }): Promise; +} + +export interface IResolveSchema extends SchemaDocument { + proof: DocumentProof; } diff --git a/src/schema/schema.ts b/src/schema/schema.ts index 8eca4f5..1e93770 100644 --- a/src/schema/schema.ts +++ b/src/schema/schema.ts @@ -4,15 +4,21 @@ * Author: Hypermine Core Team */ -import { Schema, SchemaDocument, SchemaProof, SchemaProperty } from '../../libs/generated/ssi/schema'; +import { + CredentialSchemaState as Schema, + CredentialSchemaDocument as SchemaDocument, + CredentialSchemaProperty as SchemaProperty, +} from '../../libs/generated/ssi/credential_schema'; +import { DocumentProof as SchemaProof } from '../../libs/generated/ssi/proof'; import { SchemaRpc } from './schemaRPC'; import * as constants from '../constants'; -import { ISchemaFields, ISchemaMethods } from './ISchema'; +import { ISchemaFields, ISchemaMethods, IResolveSchema } from './ISchema'; import Utils from '../utils'; import { OfflineSigner } from '@cosmjs/proto-signing'; import { DeliverTxResponse } from '@cosmjs/stargate'; import SchemaApiService from '../ssiApi/services/schema/schema.service'; const ed25519 = require('@stablelib/ed25519'); +import { base58btc } from 'multiformats/bases/base58'; export default class HyperSignSchema implements ISchemaMethods { type: string; @@ -143,7 +149,7 @@ export default class HyperSignSchema implements ISchemaMethods { t[schemaPropsObj.propName] = schemaPropsObj.val; if (prop.isRequired) { - this.schema.required.push(prop.name); + (this.schema.required as string[]).push(prop.name); } }); @@ -173,7 +179,7 @@ export default class HyperSignSchema implements ISchemaMethods { privateKeyMultibase: string; schema: SchemaDocument; verificationMethodId: string; - }): Promise { + }): Promise { if (!params.privateKeyMultibase) throw new Error('HID-SSI-SDK:: Error: params.privateKeyMultibase must be passed'); if (!params.verificationMethodId) throw new Error('HID-SSI-SDK:: Error: params.verificationMethodId must be passed'); @@ -184,8 +190,8 @@ export default class HyperSignSchema implements ISchemaMethods { privKey: params.privateKeyMultibase, }); - const schemaDoc = params.schema as Schema; - const dataBytes = (await Schema.encode(schemaDoc)).finish(); + const schemaDoc: SchemaDocument = params.schema; + const dataBytes = (await SchemaDocument.encode(schemaDoc)).finish(); const signed = ed25519.sign(privateKeyMultibaseConverted, dataBytes); const proof: SchemaProof = { @@ -193,11 +199,12 @@ export default class HyperSignSchema implements ISchemaMethods { created: this._getDateTime(), verificationMethod: params.verificationMethodId, proofPurpose: constants.SCHEMA.PROOF_PURPOSE, - proofValue: Buffer.from(signed).toString('base64'), + proofValue: base58btc.encode(signed), }; - schemaDoc.proof = {} as SchemaProof; - Object.assign(schemaDoc.proof, { ...proof }); - return schemaDoc; + schemaDoc['proof'] = {} as SchemaProof; + const schemaToReturn: IResolveSchema = schemaDoc as IResolveSchema; + Object.assign(schemaToReturn['proof'], { ...proof }); + return schemaToReturn; } /** @@ -208,13 +215,14 @@ export default class HyperSignSchema implements ISchemaMethods { */ public async register(params: { schema: Schema }): Promise<{ transactionHash: string }> { if (!params.schema) throw new Error('HID-SSI-SDK:: Error: schema must be passed'); - if (!params.schema.proof) throw new Error('HID-SSI-SDK:: Error: schema.proof must be passed'); - if (!params.schema.proof.created) throw new Error('HID-SSI-SDK:: Error: schema.proof must Contain created'); - if (!params.schema.proof.proofPurpose) + if (!params.schema['proof']) throw new Error('HID-SSI-SDK:: Error: schema.proof must be passed'); + if (!params.schema['proof'].created) throw new Error('HID-SSI-SDK:: Error: schema.proof must Contain created'); + if (!params.schema['proof'].proofPurpose) throw new Error('HID-SSI-SDK:: Error: schema.proof must Contain proofPurpose'); - if (!params.schema.proof.proofValue) throw new Error('HID-SSI-SDK:: Error: schema.proof must Contain proofValue'); - if (!params.schema.proof.type) throw new Error('HID-SSI-SDK:: Error: schema.proof must Contain type'); - if (!params.schema.proof.verificationMethod) + if (!params.schema['proof'].proofValue) + throw new Error('HID-SSI-SDK:: Error: schema.proof must Contain proofValue'); + if (!params.schema['proof'].type) throw new Error('HID-SSI-SDK:: Error: schema.proof must Contain type'); + if (!params.schema['proof'].verificationMethod) throw new Error('HID-SSI-SDK:: Error: schema.proof must Contain verificationMethod'); if (!this.schemaRpc && !this.schemaApiService) { @@ -223,13 +231,16 @@ export default class HyperSignSchema implements ISchemaMethods { ); } const response = {} as { transactionHash: string }; + const schemaDoc = params.schema; + const proof = schemaDoc['proof']; + delete schemaDoc['proof']; if (this.schemaRpc) { - const result: DeliverTxResponse = await this.schemaRpc.createSchema(params.schema, params.schema.proof); + const result: DeliverTxResponse = await this.schemaRpc.createSchema(schemaDoc as SchemaDocument, proof); response.transactionHash = result.transactionHash; } else if (this.schemaApiService) { const result: { transactionHash: string } = await this.schemaApiService.registerSchema({ schemaDocument: params.schema, - schemaProof: params.schema.proof, + schemaProof: params.schema['proof'], }); response.transactionHash = result.transactionHash; } @@ -240,9 +251,9 @@ export default class HyperSignSchema implements ISchemaMethods { * Resolves a schema document with schemId from Hypersign blockchain - an onchain activity * @params * - params.schemaId : Id of the schema document - * @returns {Promise} Returns schema document + * @returns {Promise} Returns schema document */ - public async resolve(params: { schemaId: string }): Promise { + public async resolve(params: { schemaId: string }): Promise { if (!params.schemaId) throw new Error('HID-SSI-SDK:: Error: SchemaId must be passed'); if (!this.schemaRpc) { @@ -255,6 +266,10 @@ export default class HyperSignSchema implements ISchemaMethods { throw new Error('HID-SSI-SDK:: Error: No schema found, id = ' + params.schemaId); } const schema = schemaArr[0] as Schema; - return schema; + const response: IResolveSchema = { + ...schema.credentialSchemaDocument, + proof: schema.credentialSchemaProof as SchemaProof, + }; + return response; } } diff --git a/src/schema/schemaRPC.ts b/src/schema/schemaRPC.ts index abb4033..ca0df19 100644 --- a/src/schema/schemaRPC.ts +++ b/src/schema/schemaRPC.ts @@ -9,11 +9,13 @@ import * as generatedProto from '../../libs/generated/ssi/tx'; import { OfflineSigner } from '@cosmjs/proto-signing'; import axios from 'axios'; import { HIDClient } from '../hid/client'; -import { Schema, SchemaProof } from '../../libs/generated/ssi/schema'; +import { CredentialSchemaDocument, CredentialSchemaState as Schema } from '../../libs/generated/ssi/credential_schema'; +import { DocumentProof as SchemaProof } from '../../libs/generated/ssi/proof'; import { DeliverTxResponse, SigningStargateClient } from '@cosmjs/stargate'; +import { CredentialSchemaDocument as SchemaDocument } from '../../libs/generated/ssi/credential_schema'; export interface ISchemaRPC { - createSchema(schema: Schema, proof: SchemaProof): Promise; + createSchema(schema: SchemaDocument, proof: SchemaProof): Promise; resolveSchema(schemaId: string): Promise; } @@ -45,19 +47,17 @@ export class SchemaRpc implements ISchemaRPC { await this.hidClient.init(); } - async createSchema(schema: Schema, proof: SchemaProof): Promise { + async createSchema(schema: CredentialSchemaDocument, proof: SchemaProof): Promise { if (!this.hidClient) { throw new Error('HID-SSI-SDK:: Error: SchemaRpc class is not initialise with offlinesigner'); } - - const typeUrl = `${HID_COSMOS_MODULE}.${HIDRpcEnums.MsgCreateSchema}`; - + const typeUrl = `${HID_COSMOS_MODULE}.${HIDRpcEnums.MsgRegisterCredentialSchema}`; const txMessage = { typeUrl, // Same as above - value: generatedProto[HIDRpcEnums.MsgCreateSchema].fromJSON({ - schemaDoc: schema, - schemaProof: proof, - creator: HIDClient.getHidWalletAddress(), + value: generatedProto[HIDRpcEnums.MsgRegisterCredentialSchema].fromPartial({ + credentialSchemaDocument: schema, + credentialSchemaProof: proof, + txAuthor: HIDClient.getHidWalletAddress(), }), }; @@ -71,7 +71,7 @@ export class SchemaRpc implements ISchemaRPC { async resolveSchema(schemaId: string): Promise> { const getSchemaUrl = `${this.schemaRestEp}/${schemaId}:`; const response = await axios.get(getSchemaUrl); - const { schema } = response.data; - return schema; + const { credentialSchemas } = response.data; + return credentialSchemas; } } diff --git a/src/ssiApi/services/credential/ICredentialApi.ts b/src/ssiApi/services/credential/ICredentialApi.ts index fd67c4d..7b1aa28 100644 --- a/src/ssiApi/services/credential/ICredentialApi.ts +++ b/src/ssiApi/services/credential/ICredentialApi.ts @@ -1,6 +1,6 @@ import { DeliverTxResponse } from "@cosmjs/stargate"; -import { CredentialProof, CredentialStatus } from "../../../../libs/generated/ssi/credential"; - +import { CredentialStatusDocument as CredentialStatus } from "../../../../libs/generated/ssi/credential_status"; +import { DocumentProof as CredentialProof } from "../../../../libs/generated/ssi/proof"; export interface IRegisterCredStatus { credentialStatus: CredentialStatus; credentialStatusProof: CredentialProof; diff --git a/src/ssiApi/services/did/IDIDApi.ts b/src/ssiApi/services/did/IDIDApi.ts index c392c59..3634756 100644 --- a/src/ssiApi/services/did/IDIDApi.ts +++ b/src/ssiApi/services/did/IDIDApi.ts @@ -1,11 +1,11 @@ -import { Did } from "../../../../libs/generated/ssi/did"; -import { IClientSpec, IDIDResolve, IKeyType, IVerificationRelationships } from "../../../did/IDID"; -import { ISignInfo } from '../../../did/IDID'; +import { DidDocument as Did } from "../../../../libs/generated/ssi/did"; +import { IDIDResolve, ISignInfo } from "../../../did/IDID"; +import { VerificationMethodTypes, VerificationMethodRelationships as IVerificationRelationships } from "../../../../libs/generated/ssi/client/enums"; export interface IGenerateDid{ namespace:string; methodSpecificId?:string; options?:{ - keyType:IKeyType, + keyType: VerificationMethodTypes, chainId:string, publicKey:string, walletAddress:string, diff --git a/src/ssiApi/services/did/did.service.ts b/src/ssiApi/services/did/did.service.ts index 8fc3097..74bb761 100644 --- a/src/ssiApi/services/did/did.service.ts +++ b/src/ssiApi/services/did/did.service.ts @@ -1,4 +1,4 @@ -import { Did, SignInfo } from '../../../../libs/generated/ssi/did'; +import { DidDocument as Did } from '../../../../libs/generated/ssi/did'; import { IClientSpec, IDIDResolve } from '../../../did/IDID'; import { APIENDPOINT } from '../../api-constant'; import { IAuth, IValidateAccesstokenResp } from '../../apiAuth/IAuth'; diff --git a/src/ssiApi/services/schema/ISchemaApi.ts b/src/ssiApi/services/schema/ISchemaApi.ts index bb2461e..7ba809b 100644 --- a/src/ssiApi/services/schema/ISchemaApi.ts +++ b/src/ssiApi/services/schema/ISchemaApi.ts @@ -1,6 +1,7 @@ import { DeliverTxResponse } from "@cosmjs/stargate"; -import { SchemaDocument, SchemaProof } from "../../../../libs/generated/ssi/schema"; +import { CredentialSchemaState as SchemaDocument } from "../../../../libs/generated/ssi/credential_schema"; +import { DocumentProof as SchemaProof } from '../../../../libs/generated/ssi/proof' export interface IRegisterSchema { schemaDocument: SchemaDocument, schemaProof: SchemaProof diff --git a/src/tests/config.ts b/src/tests/config.ts index 80fec1b..b839b68 100644 --- a/src/tests/config.ts +++ b/src/tests/config.ts @@ -4,16 +4,16 @@ import { HdPath, Slip10RawIndex } from '@cosmjs/crypto'; export const mnemonic = 'verify sustain lumber boat demise parade special soft bargain scout spoil there addict move badge rebuild horn achieve hollow acquire glide bundle curious present'; -export const hidNodeEp = { - rpc: 'https://rpc.jagrat.hypersign.id', - rest: 'https://api.jagrat.hypersign.id', - namespace: 'testnet', -}; // export const hidNodeEp = { -// rpc: 'http://localhost:26657', -// rest: 'http://localhost:1317', +// rpc: 'https://rpc.jagrat.hypersign.id', +// rest: 'https://api.jagrat.hypersign.id', // namespace: 'testnet', // }; +export const hidNodeEp = { + rpc: 'http://localhost:26657', + rest: 'http://localhost:1317', + namespace: 'testnet', +}; export function makeCosmoshubPath(a) { return [ Slip10RawIndex.hardened(44), diff --git a/src/tests/credential/vc.spec.ts b/src/tests/credential/vc.spec.ts index ca55414..fb06ce3 100644 --- a/src/tests/credential/vc.spec.ts +++ b/src/tests/credential/vc.spec.ts @@ -2,8 +2,8 @@ import { expect, should } from 'chai'; import { HypersignDID, HypersignSchema, HypersignVerifiableCredential } from '../../index'; import { createWallet, mnemonic, hidNodeEp } from '../config'; import { ICredentialStatus, IVerifiableCredential } from '../../credential/ICredential'; -import { CredentialProof, CredentialStatus } from '../../../libs/generated/ssi/credential'; - +import { CredentialStatusDocument as CredentialStatus } from '../../../libs/generated/ssi/credential_status'; +import { DocumentProof as CredentialProof } from '../../../libs/generated/ssi/proof'; let privateKeyMultibase; let publicKeyMultibase; let didDocId; @@ -28,6 +28,7 @@ let credenStatus: ICredentialStatus; let credentialStatusProof2 = {}; let credentialStatus2 = {}; let credentialStatus; +let didDocument2; const entityApiSecretKey = '57ed4af5b3f51428250e76a769ce8.d8f70a64e3d060b377c85eb75b60ae25011ecebb63f28a27f72183e5bcba140222f8628f17a72eee4833a9174f5ae8309'; const credentialBody = { @@ -92,6 +93,7 @@ describe('DID Opearations', () => { it('should be able to generate didDocument', async function () { didDocument = await hypersignDID.generate({ publicKeyMultibase }); didDocId = didDocument['id']; + console.log(didDocId) verificationMethodId = didDocument['verificationMethod'][0].id; expect(didDocument).to.be.a('object'); should().exist(didDocument['@context']); @@ -99,6 +101,32 @@ describe('DID Opearations', () => { should().exist(didDocument['controller']); should().exist(didDocument['alsoKnownAs']); + should().exist(didDocument['verificationMethod']); + expect( + didDocument['verificationMethod'] && + didDocument['authentication'] && + didDocument['assertionMethod'] && + didDocument['keyAgreement'] && + didDocument['capabilityInvocation'] && + didDocument['capabilityDelegation'] && + didDocument['service'] + ).to.be.a('array'); + should().exist(didDocument['authentication']); + should().exist(didDocument['assertionMethod']); + should().exist(didDocument['keyAgreement']); + should().exist(didDocument['capabilityInvocation']); + should().exist(didDocument['capabilityDelegation']); + should().exist(didDocument['service']); + }); + it('should be able to generate didDocument', async function () { + const kp = await hypersignDID.generateKeys(); + didDocument2 = await hypersignDID.generate({ publicKeyMultibase: kp.publicKeyMultibase }); + expect(didDocument).to.be.a('object'); + should().exist(didDocument['@context']); + should().exist(didDocument['id']); + should().exist(didDocument['controller']); + should().exist(didDocument['alsoKnownAs']); + should().exist(didDocument['verificationMethod']); expect( didDocument['verificationMethod'] && @@ -154,7 +182,9 @@ describe('DID Opearations', () => { describe('#register() this is to register did on the blockchain', function () { it('should be able to register didDocument in the blockchain', async function () { - const result = await hypersignDID.register({ didDocument, privateKeyMultibase, verificationMethodId }); + const didDoc = didDocument + delete didDoc.proof + const result = await hypersignDID.register({ didDocument: didDoc, privateKeyMultibase, verificationMethodId }); should().exist(result.transactionHash); should().exist(result.didDocument); }); @@ -210,7 +240,7 @@ describe('Verifiable Credential Opearations', () => { it('should not be able to generate new credential for a schema as both subjectDid and subjectDidDocSigned is passed', async function () { const tempCredentialBody = { ...credentialBody }; tempCredentialBody.issuerDid = didDocId; - tempCredentialBody.subjectDid = didDocId; + tempCredentialBody.subjectDid = didDocument2.id; tempCredentialBody['subjectDidDocSigned'] = signedDocument; return hypersignVC.generate(tempCredentialBody).catch(function (err) { expect(function () { @@ -255,7 +285,7 @@ describe('Verifiable Credential Opearations', () => { const tempCredentialBody = { ...credentialBody }; tempCredentialBody.schemaId = schemaId; tempCredentialBody.issuerDid = didDocId; - tempCredentialBody['subjectDid'] = didDocId; + tempCredentialBody['subjectDid'] = didDocument2.id; return hypersignVC.generate(tempCredentialBody).catch(function (err) { expect(function () { throw err; @@ -304,25 +334,22 @@ describe('Verifiable Credential Opearations', () => { const expirationDate = new Date('12/11/2027'); const tempCredentialBody = { ...credentialBody }; tempCredentialBody.schemaId = schemaId; - tempCredentialBody.subjectDid = didDocId; + tempCredentialBody.subjectDid = didDocument2.id; tempCredentialBody['expirationDate'] = expirationDate.toString(); tempCredentialBody.issuerDid = didDocId; tempCredentialBody.fields = { name: 'varsha' }; credentialDetail = await hypersignVC.generate(tempCredentialBody); // console.log('New Credential --------------------------------'); - // console.log(JSON.stringify(credentialDetail, null, 2)); expect(credentialDetail).to.be.a('object'); should().exist(credentialDetail['@context']); should().exist(credentialDetail['id']); credentialId = credentialDetail.id; should().exist(credentialDetail['type']); - should().exist(credentialDetail['expirationDate']); should().exist(credentialDetail['issuanceDate']); should().exist(credentialDetail['issuer']); should().exist(credentialDetail['credentialSubject']); - should().exist(credentialDetail['credentialSchema']); should().exist(credentialDetail['credentialStatus']); expect(credentialDetail['credentialStatus'].type).to.be.equal('CredentialStatusList2017'); }); @@ -331,7 +358,7 @@ describe('Verifiable Credential Opearations', () => { const expirationDate = new Date('12/11/2027'); const tempCredentialBody = { ...credentialBody }; tempCredentialBody.schemaId = schemaId; - tempCredentialBody.subjectDid = didDocId; + tempCredentialBody.subjectDid = didDocument2.id; tempCredentialBody['expirationDate'] = expirationDate.toString(); tempCredentialBody.issuerDid = didDocId; tempCredentialBody.fields = { name: 'varsha' }; @@ -343,7 +370,6 @@ describe('Verifiable Credential Opearations', () => { should().exist(credentialDetail['@context']); should().exist(credentialDetail['id']); should().exist(credentialDetail['type']); - should().exist(credentialDetail['expirationDate']); should().exist(credentialDetail['issuanceDate']); should().exist(credentialDetail['issuer']); should().exist(credentialDetail['credentialSubject']); @@ -368,7 +394,6 @@ describe('Verifiable Credential Opearations', () => { should().exist(credentialDetail['@context']); should().exist(credentialDetail['id']); should().exist(credentialDetail['type']); - should().exist(credentialDetail['expirationDate']); should().exist(credentialDetail['issuanceDate']); should().exist(credentialDetail['issuer']); should().exist(credentialDetail['credentialSubject']); @@ -436,7 +461,6 @@ describe('Verifiable Credential Opearations', () => { tempIssueCredentialBody.privateKeyMultibase = privateKeyMultibase; // console.log(JSON.stringify(tempIssueCredentialBody, null, 2)); const issuedCredResult = await hypersignVC.issue(tempIssueCredentialBody); - const { signedCredential, credentialStatus, credentialStatusProof, credentialStatusRegistrationResult } = issuedCredResult; @@ -453,7 +477,6 @@ describe('Verifiable Credential Opearations', () => { should().exist(signedCredential['@context']); should().exist(signedCredential['id']); should().exist(signedCredential['type']); - should().exist(signedCredential['expirationDate']); should().exist(signedCredential['issuanceDate']); should().exist(signedCredential['issuer']); should().exist(signedCredential['credentialSubject']); @@ -464,16 +487,17 @@ describe('Verifiable Credential Opearations', () => { expect(signedCredential['id']).to.be.equal(tempIssueCredentialBody.credential.id); expect(credentialStatus).to.be.a('object'); - should().exist(credentialStatus['claim']); + should().exist(credentialStatus['id']); + should().exist(credentialStatus['issuer']); + should().exist(credentialStatus['issuanceDate']); should().exist(credentialStatus['issuer']); should().exist(credentialStatus['issuanceDate']); - should().exist(credentialStatus['expirationDate']); - should().exist(credentialStatus['credentialHash']); + should().exist(credentialStatus['revoked']); + should().exist(credentialStatus['suspended']); expect(credentialStatusProof).to.be.a('object'); should().exist(credentialStatusProof['type']); should().exist(credentialStatusProof['created']); - should().exist(credentialStatusProof['updated']); should().exist(credentialStatusProof['verificationMethod']); should().exist(credentialStatusProof['proofPurpose']); should().exist(credentialStatusProof['proofValue']); @@ -654,7 +678,6 @@ describe('Verifiable Credential Status Opearations', () => { expect(credentialStatus.verified).to.be.equal(true); }); }); - describe('#resolveCredentialStatus this is to resolve credential status', function () { it('should not be able to resolve credential as credentialId is not passed', async function () { return hypersignVC.resolveCredentialStatus({ credentialId: '' }).catch(function (err) { @@ -665,12 +688,13 @@ describe('Verifiable Credential Status Opearations', () => { }); it('should be able to resolve credential', async function () { credentialStatus = await hypersignVC.resolveCredentialStatus({ credentialId }); - // console.log(JSON.stringify(credentialStatus, null, 2)); expect(credentialStatus).to.be.a('object'); + should().exist(credentialStatus.revoked); + should().exist(credentialStatus.suspended); + should().exist(credentialStatus.remarks); should().exist(credentialStatus.issuer); should().exist(credentialStatus.issuanceDate); - should().exist(credentialStatus.expirationDate); - should().exist(credentialStatus.credentialHash); + should().exist(credentialStatus.credentialMerkleRootHash); should().exist(credentialStatus.proof); }); }); @@ -742,6 +766,19 @@ describe('Verifiable Credential Status Opearations', () => { }).to.throw(Error, 'HID-SSI-SDK:: Error: params.status is required to update credential status'); }); }); + it('should not be able to update credential as status passed is invalid', async function () { + const tempParams = { ...params }; + tempParams.verificationMethodId = verificationMethodId; + tempParams.credentialStatus = credenStatus; + tempParams.privateKeyMultibase = privateKeyMultibase; + tempParams.issuerDid = didDocId; + tempParams.status = 'svgsdvjif'; + return hypersignVC.updateCredentialStatus(tempParams).catch(function (err) { + expect(function () { + throw err; + }).to.throw(Error, `HID-SSI-SDK:: Error: params.status is invalid`); + }); + }); it('should be able to change credential status to suspended', async function () { const credentialStatus = await hypersignVC.resolveCredentialStatus({ credentialId }); const params = { @@ -756,6 +793,7 @@ describe('Verifiable Credential Status Opearations', () => { // console.log(updatedCredResult); expect(updatedCredResult).to.be.a('object'); expect(updatedCredResult.code).to.be.equal(0); + expect(updatedCredResult.transactionHash).to.be.a('string'); }); it('should be able to change credential status to Live', async function () { @@ -765,13 +803,42 @@ describe('Verifiable Credential Status Opearations', () => { issuerDid: didDocId, verificationMethodId, privateKeyMultibase, - status: 'LIVE', + status: 'SUSPENDED', statusReason: 'Setting the status to LIVE', }; const updatedCredResult = await hypersignVC.updateCredentialStatus(params); expect(updatedCredResult).to.be.a('object'); expect(updatedCredResult.code).to.be.equal(0); }); + it('should be able to change credential status to Revoked', async function () { + const credentialStatus = await hypersignVC.resolveCredentialStatus({ credentialId }); + const params = { + credentialStatus, + issuerDid: didDocId, + verificationMethodId, + privateKeyMultibase, + status: 'REVOKED', + statusReason: 'Revoking the credential', + }; + const updatedCredResult = await hypersignVC.updateCredentialStatus(params); + expect(updatedCredResult).to.be.a('object'); + expect(updatedCredResult.code).to.be.equal(0); + + }); + it('should not be able to change the status of credential as it is revoked', async function () { + const params = { + credentialStatus, + issuerDid: didDocId, + verificationMethodId, + privateKeyMultibase, + status: 'SUSPENDED', + statusReason: 'Suspending this credential for some time', + }; + + return hypersignVC.updateCredentialStatus(params).catch(function (err) { + expect(err.message).to.include(`failed to execute message; message index: 0: credential status ${credentialId} could not be updated since it is revoked: invalid Credential Status`) + }); + }) }); describe('#registerCredentialStatus() method to register credential on blockchain', function () { diff --git a/src/tests/credential/vcByEntityApiKey.spec.ts b/src/tests/credential/vcByEntityApiKey.spec.ts index 69aad7a..d6f4ef8 100644 --- a/src/tests/credential/vcByEntityApiKey.spec.ts +++ b/src/tests/credential/vcByEntityApiKey.spec.ts @@ -2,7 +2,7 @@ import { expect, should } from 'chai'; import { HypersignDID, HypersignSchema, HypersignVerifiableCredential } from '../../index'; import { createWallet, mnemonic, hidNodeEp, entityApiSecret } from '../config'; import { ICredentialStatus, IVerifiableCredential } from '../../credential/ICredential'; -import { CredentialProof, CredentialStatus } from '../../../libs/generated/ssi/credential'; +// import { CredentialProof, CredentialStatus } from '../../../libs/generated/ssi/credential_status'; let didDocument; let didDocId; let privateKeyMultibase; diff --git a/src/tests/did/did.spec.ts b/src/tests/did/did.spec.ts index 1a07041..2101927 100644 --- a/src/tests/did/did.spec.ts +++ b/src/tests/did/did.spec.ts @@ -1,8 +1,9 @@ import { expect, should } from 'chai'; import { HypersignDID, HypersignSSISdk } from '../../index'; -import { IPublicKey, IController, IDID, IKeyType } from '../../did/IDID'; +import { IPublicKey, IController } from '../../did/IDID'; import { createWallet, mnemonic, hidNodeEp } from '../config'; +import { VerificationMethodTypes } from '../../../libs/generated/ssi/client/enums'; let privateKeyMultibase; let publicKeyMultibase; let verificationMethodId; @@ -272,7 +273,7 @@ describe('DID Test scenarios', () => { it('should not be able to add verificationMethod as params.did is passed but yet not registerd', async () => { const params = { did: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY', - type: IKeyType.Ed25519VerificationKey2020, + type: VerificationMethodTypes.Ed25519VerificationKey2020, id: 'did:hid:testnet:z8wo3LVRR4JkEguESX6hf4EBc234refrdan5xVD49quCPV7fBHYdY#key-1', publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', }; @@ -375,46 +376,46 @@ describe('DID Test scenarios', () => { }); }); - it('should be able to add verification method of type X25519KeyAgreementKey2020 in didDocument', async () => { - const params = { - didDocument: didDocument, - type: 'X25519KeyAgreementKey2020', - publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', - }; - const didDoc = JSON.parse(JSON.stringify(didDocument)); - - const updatedDidDoc = await hypersignDID.addVerificationMethod({ ...params }); - expect(updatedDidDoc).to.be.a('object'); - should().exist(updatedDidDoc['context']); - should().exist(updatedDidDoc['id']); - should().exist(updatedDidDoc['controller']); - should().exist(updatedDidDoc['alsoKnownAs']); - should().exist(updatedDidDoc['verificationMethod']); - expect( - updatedDidDoc['verificationMethod'] && - updatedDidDoc['authentication'] && - updatedDidDoc['assertionMethod'] && - updatedDidDoc['keyAgreement'] && - updatedDidDoc['capabilityInvocation'] && - updatedDidDoc['capabilityDelegation'] && - updatedDidDoc['service'] - ).to.be.a('array'); - should().exist(updatedDidDoc['authentication']); - should().exist(updatedDidDoc['assertionMethod']); - expect(updatedDidDoc.verificationMethod.length).to.be.greaterThan(didDoc.verificationMethod.length); - }); + // it('should be able to add verification method of type X25519KeyAgreementKey2020 in didDocument', async () => { + // const params = { + // didDocument: didDocument, + // type: 'X25519KeyAgreementKey2020', + // publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', + // }; + // const didDoc = JSON.parse(JSON.stringify(didDocument)); + // const updatedDidDoc = await hypersignDID.addVerificationMethod({ ...params }); + // console.log(didDocument, "add vm ") + // expect(updatedDidDoc).to.be.a('object'); + // should().exist(updatedDidDoc['@context']); + // should().exist(updatedDidDoc['id']); + // should().exist(updatedDidDoc['controller']); + // should().exist(updatedDidDoc['alsoKnownAs']); + // should().exist(updatedDidDoc['verificationMethod']); + // expect( + // updatedDidDoc['verificationMethod'] && + // updatedDidDoc['authentication'] && + // updatedDidDoc['assertionMethod'] && + // updatedDidDoc['keyAgreement'] && + // updatedDidDoc['capabilityInvocation'] && + // updatedDidDoc['capabilityDelegation'] && + // updatedDidDoc['service'] + // ).to.be.a('array'); + // should().exist(updatedDidDoc['authentication']); + // should().exist(updatedDidDoc['assertionMethod']); + // expect(updatedDidDoc.verificationMethod.length).to.be.greaterThan(didDoc.verificationMethod.length); + // }); it('should be able to add verification method in didDocument without offlinesigner', async () => { const hypersignDid = new HypersignDID({ namespace: 'testnet' }); const didDoc = JSON.parse(JSON.stringify(didDocument)); const params = { didDocument: didDoc, - type: IKeyType.X25519KeyAgreementKey2020, + type: VerificationMethodTypes.X25519KeyAgreementKey2020, publicKeyMultibase: '23fer44374u3rmhvf47ri35ty', }; const testDidDoc = await hypersignDid.addVerificationMethod(params); expect(testDidDoc).to.be.a('object'); - should().exist(testDidDoc['context']); + should().exist(testDidDoc['@context']); should().exist(testDidDoc['id']); should().exist(testDidDoc['controller']); should().exist(testDidDoc['alsoKnownAs']); @@ -442,7 +443,7 @@ describe('DID Test scenarios', () => { DIdDOcWithMultiplVM = await hypersignDID.addVerificationMethod(params); expect(DIdDOcWithMultiplVM).to.be.a('object'); - should().exist(DIdDOcWithMultiplVM['context']); + should().exist(DIdDOcWithMultiplVM['@context']); should().exist(DIdDOcWithMultiplVM['id']); should().exist(DIdDOcWithMultiplVM['controller']); should().exist(DIdDOcWithMultiplVM['alsoKnownAs']); @@ -665,7 +666,9 @@ describe('DID Test scenarios', () => { }); it('should not be able to update did document as versionId passed is incorrect', function () { const updateBody = { didDocument, privateKeyMultibase, verificationMethodId, versionId: '1.0.1' }; - didDocument['alsoKnownAs'].push('Random Data'); + const didDoc = JSON.parse(JSON.stringify(didDocument)) + updateBody['didDocument'] = didDoc + updateBody['didDocument']['alsoKnownAs'].push('Random Data'); return hypersignDID.update(updateBody).catch(function (err) { expect(function () { throw err; @@ -676,9 +679,10 @@ describe('DID Test scenarios', () => { }); }); it('should be able to update did document', async function () { - didDocument['alsoKnownAs'].push('Some DATA'); + const didDoc = JSON.parse(JSON.stringify(didDocument)) + didDoc['alsoKnownAs'].push('Some DATA'); const result = await hypersignDID.update({ - didDocument, + didDocument: didDoc, privateKeyMultibase, verificationMethodId, versionId, @@ -695,7 +699,6 @@ describe('DID Test scenarios', () => { expect(result).to.be.a('object'); expect(result.didDocument.id).to.be.equal(didDocId); expect(result.didDocumentMetadata).to.be.a('object'); - expect(result.didDocument.verificationMethod[0].publicKeyMultibase).to.be.not.equal(publicKeyMultibase); versionId = result.didDocumentMetadata.versionId; }); // should we able to get same publicKeyMultibase as generated in the begining in didDoc @@ -714,7 +717,6 @@ describe('DID Test scenarios', () => { it('should be able to resolve DID even without offline signer passed to the constructor; making resolve RPC offchain activity', async function () { const hypersignDID = new HypersignDID(); - const params = { did: didDocId, ed25519verificationkey2020: true, @@ -724,7 +726,6 @@ describe('DID Test scenarios', () => { expect(result).to.be.a('object'); expect(result.didDocument.id).to.be.equal(didDocId); expect(result.didDocumentMetadata).to.be.a('object'); - expect(result.didDocument.verificationMethod[0].publicKeyMultibase).to.be.equal(publicKeyMultibase); }); }); describe('#deactivate() this is to deactivate didDocument based on didDocId', function () { @@ -756,7 +757,8 @@ describe('DID Test scenarios', () => { }); }); it('should not be able to deactivate did document as versionId pased is incorrect', function () { - const deactivateBody = { didDocument, privateKeyMultibase, verificationMethodId, versionId: '1.0.1' }; + const didDoc = JSON.parse(JSON.stringify(didDocument)) + const deactivateBody = { didDocument: didDoc, privateKeyMultibase, verificationMethodId, versionId: '1.0.1' }; return hypersignDID.deactivate(deactivateBody).catch(function (err) { expect(function () { throw err; @@ -767,8 +769,9 @@ describe('DID Test scenarios', () => { }); }); it('should be able to deactivate did document', async function () { + const didDocTodeactivate = JSON.parse(JSON.stringify(didDocument)) const result = await hypersignDID.deactivate({ - didDocument, + didDocument: didDocTodeactivate, privateKeyMultibase, verificationMethodId, versionId, diff --git a/src/tests/schema/schema.spec.ts b/src/tests/schema/schema.spec.ts index f5a91ce..84da9e3 100644 --- a/src/tests/schema/schema.spec.ts +++ b/src/tests/schema/schema.spec.ts @@ -1,16 +1,16 @@ import { expect, should } from 'chai'; -import { HypersignSSISdk, HypersignDID, HypersignSchema } from '../../index'; +import { HypersignDID, HypersignSchema } from '../../index'; import { createWallet, mnemonic, hidNodeEp } from '../config'; -import { Schema, SchemaProof, SchemaDocument } from '../../../libs/generated/ssi/schema'; +import { CredentialSchemaState as Schema } from '../../../libs/generated/ssi/credential_schema'; +import { DocumentProof as SchemaProof } from '../../../libs/generated/ssi/proof'; + -let hsSdk; let privateKeyMultibase; let publicKeyMultibase; let verificationMethodId; let didDocument; let didDocId; let offlineSigner; -let schemaSignature; let hypersignSchema; let schemaObject; let schemaId; @@ -18,7 +18,7 @@ let verificationMethod; let hypersignDID; let signedSchema; const signSchema = {} as Schema; -signSchema.proof = {} as SchemaProof; +signSchema['proof'] = {} as SchemaProof; const schemaBody = { name: 'testSchema', description: 'This is a test schema generation', @@ -31,8 +31,6 @@ const schemaBody = { beforeEach(async function () { offlineSigner = await createWallet(mnemonic); - // hsSdk = new HypersignSSISdk(offlineSigner, hidNodeEp.rpc, hidNodeEp.rest, hidNodeEp.namespace); - // await hsSdk.init(); hypersignSchema = new HypersignSchema({ // entityApiSecretKey, @@ -160,7 +158,6 @@ describe('#sign() function to sign schema', function () { schema: schemaObject, verificationMethodId: didDocument['assertionMethod'][0], }); - //onsole.log(JSON.stringify(signedSchema, null, 2)) expect(signedSchema).to.be.a('object'); should().exist(signedSchema.proof); should().exist(signedSchema.proof.type); diff --git a/src/tests/schema/schemaByEntityApiKey.spec.ts b/src/tests/schema/schemaByEntityApiKey.spec.ts index 94633da..e3fe640 100644 --- a/src/tests/schema/schemaByEntityApiKey.spec.ts +++ b/src/tests/schema/schemaByEntityApiKey.spec.ts @@ -1,7 +1,6 @@ import { expect, should } from 'chai'; import { HypersignSchema, HypersignDID } from '../../index'; import { createWallet, mnemonic, hidNodeEp, entityApiSecret } from '../config' -import { Schema, SchemaProof, SchemaDocument } from '../../../libs/generated/ssi/schema'; import HyperSignSchema from '../../schema/schema'; let signedSchema diff --git a/src/tests/vp.spec.ts b/src/tests/vp.spec.ts index 2052485..c07e754 100644 --- a/src/tests/vp.spec.ts +++ b/src/tests/vp.spec.ts @@ -173,12 +173,13 @@ describe('DID Opearations', () => { authentication: [], }; it('should able to sign did document', async function () { + const didDoc = JSON.parse(JSON.stringify(didDocument)); const params = { privateKeyMultibase: privateKeyMultibase as string, challenge: challenge as string, domain: domain as string, did: '', - didDocument: didDocument as object, + didDocument: didDoc as object, verificationMethodId: verificationMethodId as string, controller, }; @@ -292,7 +293,6 @@ describe('Verifiable Credential Opearations', () => { tempIssueCredentialBody.privateKeyMultibase = privateKeyMultibase; //console.log(JSON.stringify(tempIssueCredentialBody, null, 2)); const issuedCredResult = await hypersignVC.issue(tempIssueCredentialBody); - const { signedCredential, credentialStatus, credentialStatusProof, credentialStatusRegistrationResult } = issuedCredResult; @@ -324,21 +324,21 @@ describe('Verifiable Credential Opearations', () => { expect(signedCredential['id']).to.be.equal(tempIssueCredentialBody.credential.id); expect(credentialStatus).to.be.a('object'); - should().exist(credentialStatus['claim']); should().exist(credentialStatus['issuer']); should().exist(credentialStatus['issuanceDate']); - should().exist(credentialStatus['expirationDate']); - should().exist(credentialStatus['credentialHash']); - + should().exist(credentialStatus['revoked']); + should().exist(credentialStatus['suspended']); + should().exist(credentialStatus['remarks']); + should().exist(credentialStatus['credentialMerkleRootHash']); expect(credentialStatusProof).to.be.a('object'); should().exist(credentialStatusProof['type']); should().exist(credentialStatusProof['created']); - should().exist(credentialStatusProof['updated']); should().exist(credentialStatusProof['verificationMethod']); should().exist(credentialStatusProof['proofPurpose']); should().exist(credentialStatusProof['proofValue']); expect(credentialStatusRegistrationResult).to.be.a('object'); + should().exist(credentialStatusRegistrationResult['code']); should().exist(credentialStatusRegistrationResult['height']); should().exist(credentialStatusRegistrationResult['transactionHash']); should().exist(credentialStatusRegistrationResult['gasUsed']); diff --git a/src/utils.ts b/src/utils.ts index 1614bd2..25f0a74 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { Did } from '../libs/generated/ssi/did'; +import { DidDocument as Did } from '../libs/generated/ssi/did'; import * as constants from './constants'; const { encode, decode } = require('base58-universal'); import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020';