@keetanetwork/anchor 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/services/kyc/common.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAyE5B,MAAM,uCAAwC,SAAQ,oBAAoB;IACzE,MAAM,CAAmB,IAAI,GAAW,yCAAyC,CAAC;IACjE,mDAAmD,CAAU;IACtE,MAAM,CAAU,mDAAmD,GAAG,sCAAsC,CAAC;IAErH,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,2BAA2B,CAAC,CAAC;QAC9C,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QAEtB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,qDAAqD,EAAE;YAClF,KAAK,EAAE,uCAAuC,CAAC,mDAAmD;YAClG,UAAU,EAAE,KAAK;SACjB,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAc;QAC/B,OAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,qDAAqD,EAAE,uCAAuC,CAAC,mDAAmD,CAAC,CAAC,CAAC;IAC1L,CAAC;;AAGF,MAAM,sCAAuC,SAAQ,oBAAoB;IACxE,MAAM,CAAmB,IAAI,GAAW,wCAAwC,CAAC;IAChE,kDAAkD,CAAU;IACrE,MAAM,CAAU,kDAAkD,GAAG,sCAAsC,CAAC;IAEpH,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,iCAAiC,CAAC,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QAEtB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,oD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AO,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5D,MAAK,CAAC,IAAI,KAAK,CAAC,wFAAwF,CAAC,CAAC,CAAC;QAC5G,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,IAAI,CACrB;YACC,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;SAClB,EACD,OAAO,CACP,CAAC;QAEF,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;;AAGF,MAAM,CAAC,MAAM,MAAM,GAIf;IACH;;OAEG;IACH,oBAAoB,EAAE,uCAAuC;IAE7D;;;OAGG;IACH,mBAAmB,EAAE,sCAAsC;IAE3D;;OAEG;IACH,eAAe,EAAE,wCAAwC;CACzD,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAgC;IACxE,OAAM,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAA4E;IAClH,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1E,OAAM,CAAC,MAAM,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type {\n\tServiceMetadata,\n\tServiceSearchCriteria\n} from '../../lib/resolver.ts';\nimport * as KeetaNet from '@keetanetwork/keetanet-client';\nimport * as Signing from '../../lib/utils/signing.js';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\n\ntype KeetaNetToken = InstanceType<typeof KeetaNet.lib.Account<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>>;\n\nexport type CountryCodesSearchCriteria = ServiceSearchCriteria<'kyc'>['countryCodes'];\n\nexport type Operations = NonNullable<ServiceMetadata['services']['kyc']>[string]['operations'];\nexport type OperationNames = keyof Operations;\n\nexport interface KeetaKYCAnchorCreateVerificationRequest {\n\tcountryCodes: CountryCodesSearchCriteria;\n\taccount: ReturnType<InstanceType<typeof KeetaNet.lib.Account>['publicKeyString']['get']>;\n\tsigned: {\n\t\tnonce: string;\n\t\t/* Date and time of the request in ISO 8601 format */\n\t\ttimestamp: string;\n\t\t/* Signature of the account public key and the nonce as an ASN.1 Sequence, Base64 DER */\n\t\tsignature: string;\n\t};\n}\n\ntype KeetaNetTokenPublicKeyString = ReturnType<InstanceType<typeof KeetaNet.lib.Account<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>>['publicKeyString']['get']>;\nexport type KeetaKYCAnchorCreateVerificationResponse = ({\n\tok: true;\n\n\t/**\n\t * The ID of the verification request -- this is a unique identifier\n\t * for the verification request that can be used to fetch the\n\t * certificate later\n\t */\n\tid: string;\n\t/**\n\t * The expected cost of the verification request, in the form of a\n\t * token and a range of minimum and maximum expected costs\n\t */\n\texpectedCost: {\n\t\tmin: string;\n\t\tmax: string;\n\t\ttoken: KeetaNetTokenPublicKeyString;\n\t};\n\t/**\n\t * The URL to the verification service where the user can complete the\n\t * verification process. This URL is expected to be a web URL that the\n\t * user can visit to complete the verification.\n\t */\n\twebURL: string;\n} | {\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaKYCAnchorGetCertificateResponse = ({\n\tok: true;\n\t/**\n\t * The certificates that were issued by the KYC Anchor service.\n\t * Typically this will just be a single certificate, but\n\t * it could also be multiple certificates if the service\n\t * issues multiple certificates for a single verification.\n\t *\n\t * Each certificate is represented as a PEM-encoded string.\n\t * The `intermediates` field is optional and may contain\n\t * additional intermediate certificates that are required to\n\t * validate the certificate chain.\n\t */\n\tresults: ({\n\t\tcertificate: string;\n\t\tintermediates?: string[];\n\t})[];\n} | {\n\tok: false;\n\terror: string;\n});\n\nclass KeetaKYCAnchorVerificationNotFoundError extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorVerificationNotFoundError';\n\tprivate readonly KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID = '79d7036f-58ad-4eec-b64c-26bdf98cd3c1';\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'Verification ID not found');\n\t\tthis.statusCode = 400;\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorVerificationNotFoundError.KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorVerificationNotFoundError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID', KeetaKYCAnchorVerificationNotFoundError.KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID));\n\t}\n}\n\nclass KeetaKYCAnchorCertificateNotFoundError extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorCertificateNotFoundError';\n\tprivate readonly KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID = '6f4d9620-df33-468e-ae03-898d4fa67aeb';\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'Certificate not found (pending)');\n\t\tthis.statusCode = 404;\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorCertificateNotFoundError.KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorCertificateNotFoundError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID', KeetaKYCAnchorCertificateNotFoundError.KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID));\n\t}\n}\n\nclass KeetaKYCAnchorCertificatePaymentRequired extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorCertificatePaymentRequired';\n\tprivate readonly KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID = '92b2481d-b29b-4fa2-a295-3a47d99c0869';\n\treadonly amount: bigint;\n\treadonly token: KeetaNetToken;\n\n\tconstructor(cost: { amount: bigint | string; token: KeetaNetToken | string; }, message?: string) {\n\t\tsuper(message ?? 'Payment required for certificate');\n\t\tthis.statusCode = 402;\n\n\t\tthis.amount = BigInt(cost.amount);\n\t\tthis.token = KeetaNet.lib.Account.toAccount<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>(cost.token);\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorCertificatePaymentRequired.KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorCertificatePaymentRequired {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID', KeetaKYCAnchorCertificatePaymentRequired.KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID));\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\tlet message = this.message;\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\tok: false,\n\t\t\t\tcode: 'KEETA_ANCHOR_KYC_PAYMENT_REQUIRED',\n\t\t\t\tdata: {\n\t\t\t\t\tcost: {\n\t\t\t\t\t\tamount: `0x${this.amount.toString(16)}`,\n\t\t\t\t\t\ttoken: this.token.publicKeyString.get()\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\terror: this.message\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): { ok: false; retryable: boolean; error: string; name: string; statusCode: number; amount: string; token: string } {\n\t\treturn({\n\t\t\tok: false,\n\t\t\tretryable: this.retryable,\n\t\t\terror: this.message,\n\t\t\tname: this.name,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tamount: `0x${this.amount.toString(16)}`,\n\t\t\ttoken: this.token.publicKeyString.get()\n\t\t});\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaKYCAnchorCertificatePaymentRequired> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\t// Extract required properties specific to PaymentRequired\n\t\tif (!('amount' in other) || typeof other.amount !== 'string') {\n\t\t\tthrow(new Error('Invalid KeetaKYCAnchorCertificatePaymentRequired JSON object: missing or invalid amount'));\n\t\t}\n\n\t\tif (!('token' in other) || typeof other.token !== 'string') {\n\t\t\tthrow(new Error('Invalid KeetaKYCAnchorCertificatePaymentRequired JSON object: missing or invalid token'));\n\t\t}\n\n\t\tconst error = new this(\n\t\t\t{\n\t\t\t\tamount: other.amount,\n\t\t\t\ttoken: other.token\n\t\t\t},\n\t\t\tmessage\n\t\t);\n\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\nexport const Errors: {\n\tVerificationNotFound: typeof KeetaKYCAnchorVerificationNotFoundError;\n\tCertificateNotFound: typeof KeetaKYCAnchorCertificateNotFoundError;\n\tPaymentRequired: typeof KeetaKYCAnchorCertificatePaymentRequired;\n} = {\n\t/**\n\t * The verification ID was not found\n\t */\n\tVerificationNotFound: KeetaKYCAnchorVerificationNotFoundError,\n\n\t/**\n\t * The certificate for the verification ID was not found\n\t * (typically this means the verification is still pending)\n\t */\n\tCertificateNotFound: KeetaKYCAnchorCertificateNotFoundError,\n\n\t/**\n\t * Payment is required for the certificate\n\t */\n\tPaymentRequired: KeetaKYCAnchorCertificatePaymentRequired\n}\n\nexport async function generateSignedData(account: Signing.SignableAccount): Promise<{ nonce: string; timestamp: string; signature: string; }> {\n\treturn(await Signing.SignData(account, []));\n}\n\nexport async function verifySignedData(request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'account' | 'signed'>): Promise<boolean> {\n\tconst account = KeetaNet.lib.Account.fromPublicKeyString(request.account);\n\treturn(await Signing.VerifySignedData(account, [], request.signed));\n}\n"]}
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/services/kyc/common.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAC1D,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAC;AACtD,OAAO,EACN,oBAAoB,EACpB,MAAM,oBAAoB,CAAC;AAyE5B,MAAM,uCAAwC,SAAQ,oBAAoB;IACzE,MAAM,CAAmB,IAAI,GAAW,yCAAyC,CAAC;IACjE,mDAAmD,CAAU;IACtE,MAAM,CAAU,mDAAmD,GAAG,sCAAsC,CAAC;IACnG,QAAQ,GAAG,OAAO,CAAC;IAErC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,2BAA2B,CAAC,CAAC;QAC9C,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;QAEtB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,qDAAqD,EAAE;YAClF,KAAK,EAAE,uCAAuC,CAAC,mDAAmD;YAClG,UAAU,EAAE,KAAK;SACjB,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAc;QAC/B,OAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,qDAAqD,EAAE,uCAAuC,CAAC,mDAAmD,CAAC,CAAC,CAAC;IAC1L,CAAC;;AAGF,MAA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AAC,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type {\n\tServiceMetadata,\n\tServiceSearchCriteria\n} from '../../lib/resolver.ts';\nimport * as KeetaNet from '@keetanetwork/keetanet-client';\nimport * as Signing from '../../lib/utils/signing.js';\nimport {\n\tKeetaAnchorUserError\n} from '../../lib/error.js';\n\ntype KeetaNetToken = InstanceType<typeof KeetaNet.lib.Account<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>>;\n\nexport type CountryCodesSearchCriteria = ServiceSearchCriteria<'kyc'>['countryCodes'];\n\nexport type Operations = NonNullable<ServiceMetadata['services']['kyc']>[string]['operations'];\nexport type OperationNames = keyof Operations;\n\nexport interface KeetaKYCAnchorCreateVerificationRequest {\n\tcountryCodes: CountryCodesSearchCriteria;\n\taccount: ReturnType<InstanceType<typeof KeetaNet.lib.Account>['publicKeyString']['get']>;\n\tsigned: {\n\t\tnonce: string;\n\t\t/* Date and time of the request in ISO 8601 format */\n\t\ttimestamp: string;\n\t\t/* Signature of the account public key and the nonce as an ASN.1 Sequence, Base64 DER */\n\t\tsignature: string;\n\t};\n}\n\ntype KeetaNetTokenPublicKeyString = ReturnType<InstanceType<typeof KeetaNet.lib.Account<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>>['publicKeyString']['get']>;\nexport type KeetaKYCAnchorCreateVerificationResponse = ({\n\tok: true;\n\n\t/**\n\t * The ID of the verification request -- this is a unique identifier\n\t * for the verification request that can be used to fetch the\n\t * certificate later\n\t */\n\tid: string;\n\t/**\n\t * The expected cost of the verification request, in the form of a\n\t * token and a range of minimum and maximum expected costs\n\t */\n\texpectedCost: {\n\t\tmin: string;\n\t\tmax: string;\n\t\ttoken: KeetaNetTokenPublicKeyString;\n\t};\n\t/**\n\t * The URL to the verification service where the user can complete the\n\t * verification process. This URL is expected to be a web URL that the\n\t * user can visit to complete the verification.\n\t */\n\twebURL: string;\n} | {\n\tok: false;\n\terror: string;\n});\n\nexport type KeetaKYCAnchorGetCertificateResponse = ({\n\tok: true;\n\t/**\n\t * The certificates that were issued by the KYC Anchor service.\n\t * Typically this will just be a single certificate, but\n\t * it could also be multiple certificates if the service\n\t * issues multiple certificates for a single verification.\n\t *\n\t * Each certificate is represented as a PEM-encoded string.\n\t * The `intermediates` field is optional and may contain\n\t * additional intermediate certificates that are required to\n\t * validate the certificate chain.\n\t */\n\tresults: ({\n\t\tcertificate: string;\n\t\tintermediates?: string[];\n\t})[];\n} | {\n\tok: false;\n\terror: string;\n});\n\nclass KeetaKYCAnchorVerificationNotFoundError extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorVerificationNotFoundError';\n\tprivate readonly KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID = '79d7036f-58ad-4eec-b64c-26bdf98cd3c1';\n\toverride readonly logLevel = 'DEBUG';\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'Verification ID not found');\n\t\tthis.statusCode = 400;\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorVerificationNotFoundError.KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorVerificationNotFoundError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID', KeetaKYCAnchorVerificationNotFoundError.KeetaKYCAnchorVerificationNotFoundErrorObjectTypeID));\n\t}\n}\n\nclass KeetaKYCAnchorCertificateNotFoundError extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorCertificateNotFoundError';\n\tprivate readonly KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID = '6f4d9620-df33-468e-ae03-898d4fa67aeb';\n\n\tconstructor(message?: string) {\n\t\tsuper(message ?? 'Certificate not found (pending)');\n\t\tthis.statusCode = 404;\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorCertificateNotFoundError.KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorCertificateNotFoundError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID', KeetaKYCAnchorCertificateNotFoundError.KeetaKYCAnchorCertificateNotFoundErrorObjectTypeID));\n\t}\n}\n\nclass KeetaKYCAnchorCertificatePaymentRequired extends KeetaAnchorUserError {\n\tstatic override readonly name: string = 'KeetaKYCAnchorCertificatePaymentRequired';\n\tprivate readonly KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID!: string;\n\tprivate static readonly KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID = '92b2481d-b29b-4fa2-a295-3a47d99c0869';\n\treadonly amount: bigint;\n\treadonly token: KeetaNetToken;\n\n\tconstructor(cost: { amount: bigint | string; token: KeetaNetToken | string; }, message?: string) {\n\t\tsuper(message ?? 'Payment required for certificate');\n\t\tthis.statusCode = 402;\n\n\t\tthis.amount = BigInt(cost.amount);\n\t\tthis.token = KeetaNet.lib.Account.toAccount<typeof KeetaNet.lib.Account.AccountKeyAlgorithm.TOKEN>(cost.token);\n\n\t\tObject.defineProperty(this, 'KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID', {\n\t\t\tvalue: KeetaKYCAnchorCertificatePaymentRequired.KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaKYCAnchorCertificatePaymentRequired {\n\t\treturn(this.hasPropWithValue(input, 'KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID', KeetaKYCAnchorCertificatePaymentRequired.KeetaKYCAnchorCertificatePaymentRequiredObjectTypeID));\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\tlet message = this.message;\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\tok: false,\n\t\t\t\tcode: 'KEETA_ANCHOR_KYC_PAYMENT_REQUIRED',\n\t\t\t\tdata: {\n\t\t\t\t\tcost: {\n\t\t\t\t\t\tamount: `0x${this.amount.toString(16)}`,\n\t\t\t\t\t\ttoken: this.token.publicKeyString.get()\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\terror: this.message\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): { ok: false; retryable: boolean; error: string; name: string; statusCode: number; amount: string; token: string } {\n\t\treturn({\n\t\t\tok: false,\n\t\t\tretryable: this.retryable,\n\t\t\terror: this.message,\n\t\t\tname: this.name,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tamount: `0x${this.amount.toString(16)}`,\n\t\t\ttoken: this.token.publicKeyString.get()\n\t\t});\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaKYCAnchorCertificatePaymentRequired> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\t// Extract required properties specific to PaymentRequired\n\t\tif (!('amount' in other) || typeof other.amount !== 'string') {\n\t\t\tthrow(new Error('Invalid KeetaKYCAnchorCertificatePaymentRequired JSON object: missing or invalid amount'));\n\t\t}\n\n\t\tif (!('token' in other) || typeof other.token !== 'string') {\n\t\t\tthrow(new Error('Invalid KeetaKYCAnchorCertificatePaymentRequired JSON object: missing or invalid token'));\n\t\t}\n\n\t\tconst error = new this(\n\t\t\t{\n\t\t\t\tamount: other.amount,\n\t\t\t\ttoken: other.token\n\t\t\t},\n\t\t\tmessage\n\t\t);\n\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\nexport const Errors: {\n\tVerificationNotFound: typeof KeetaKYCAnchorVerificationNotFoundError;\n\tCertificateNotFound: typeof KeetaKYCAnchorCertificateNotFoundError;\n\tPaymentRequired: typeof KeetaKYCAnchorCertificatePaymentRequired;\n} = {\n\t/**\n\t * The verification ID was not found\n\t */\n\tVerificationNotFound: KeetaKYCAnchorVerificationNotFoundError,\n\n\t/**\n\t * The certificate for the verification ID was not found\n\t * (typically this means the verification is still pending)\n\t */\n\tCertificateNotFound: KeetaKYCAnchorCertificateNotFoundError,\n\n\t/**\n\t * Payment is required for the certificate\n\t */\n\tPaymentRequired: KeetaKYCAnchorCertificatePaymentRequired\n}\n\nexport async function generateSignedData(account: Signing.SignableAccount): Promise<{ nonce: string; timestamp: string; signature: string; }> {\n\treturn(await Signing.SignData(account, []));\n}\n\nexport async function verifySignedData(request: Pick<KeetaKYCAnchorCreateVerificationRequest, 'account' | 'signed'>): Promise<boolean> {\n\tconst account = KeetaNet.lib.Account.fromPublicKeyString(request.account);\n\treturn(await Signing.VerifySignedData(account, [], request.signed));\n}\n"]}