@trustvc/trustvc 1.4.4 → 1.4.6
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.
- package/dist/cjs/core/endorsement-chain/helpers.js +1 -1
- package/dist/esm/core/endorsement-chain/helpers.js +1 -1
- package/dist/types/core/decrypt.d.ts +12 -0
- package/dist/types/core/documentBuilder.d.ts +29 -0
- package/dist/types/core/encrypt.d.ts +12 -0
- package/dist/types/core/endorsement-chain/useEndorsementChain.d.ts +5 -0
- package/dist/types/core/verify.d.ts +21 -0
- package/dist/types/open-attestation/verify.d.ts +11 -0
- package/dist/types/open-attestation/wrap.d.ts +41 -0
- package/dist/types/utils/stringUtils/index.d.ts +25 -0
- package/dist/types/w3c/sign.d.ts +7 -0
- package/dist/types/w3c/verify.d.ts +7 -0
- package/package.json +1 -1
|
@@ -55,8 +55,8 @@ const mergeTransfersV5 = /* @__PURE__ */ __name((transferEvents) => {
|
|
|
55
55
|
if (groupedEvents.length === 1) return groupedEvents;
|
|
56
56
|
if (groupedEvents.length > 1) {
|
|
57
57
|
const { owner, holder } = getHolderOwner(groupedEvents);
|
|
58
|
-
const base = groupedEvents[0];
|
|
59
58
|
const type = identifyEventTypeFromLogs(groupedEvents);
|
|
59
|
+
const base = groupedEvents.find((event) => event.type === type) ?? groupedEvents[0];
|
|
60
60
|
return [{ ...base, owner, holder, type }];
|
|
61
61
|
}
|
|
62
62
|
throw new Error("Invalid hash, update your configuration");
|
|
@@ -53,8 +53,8 @@ const mergeTransfersV5 = /* @__PURE__ */ __name((transferEvents) => {
|
|
|
53
53
|
if (groupedEvents.length === 1) return groupedEvents;
|
|
54
54
|
if (groupedEvents.length > 1) {
|
|
55
55
|
const { owner, holder } = getHolderOwner(groupedEvents);
|
|
56
|
-
const base = groupedEvents[0];
|
|
57
56
|
const type = identifyEventTypeFromLogs(groupedEvents);
|
|
57
|
+
const base = groupedEvents.find((event) => event.type === type) ?? groupedEvents[0];
|
|
58
58
|
return [{ ...base, owner, holder, type }];
|
|
59
59
|
}
|
|
60
60
|
throw new Error("Invalid hash, update your configuration");
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decrypts a message that was encrypted using the ChaCha20 algorithm.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an encrypted message (in base64 format), converts it back to a buffer,
|
|
5
|
+
* and decrypts it using the ChaCha20 stream cipher. The decryption key is processed to ensure it's
|
|
6
|
+
* 32 bytes in length, and the nonce (initialization vector) is either provided or generated as 12 bytes.
|
|
7
|
+
* @param {string} encryptedMessage - The encrypted message to be decrypted, in base64 format.
|
|
8
|
+
* @param {string} key - The decryption key, which will be processed into a 32-byte key.
|
|
9
|
+
* @param {string} [nonce] - (Optional) A 12-byte nonce used during the encryption process. If not provided, one will be generated.
|
|
10
|
+
* @returns {string} - The decrypted message in UTF-8 format.
|
|
11
|
+
* @throws {Error} - Throws if the decryption process encounters any issues.
|
|
12
|
+
*/
|
|
1
13
|
declare function decrypt(encryptedMessage: string, key: string, nonce?: string): string;
|
|
2
14
|
|
|
3
15
|
export { decrypt };
|
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
import { PrivateKeyPair } from '@trustvc/w3c-issuer';
|
|
2
2
|
import { VerifiableCredential, SignedVerifiableCredential } from '@trustvc/w3c-vc';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for a W3C Verifiable Document using a Bitstring Status List.
|
|
6
|
+
* @property {string} url - A Verifiable Credential (VC) representing the Bitstring Status List,
|
|
7
|
+
* typically used for revocation or suspension checks.
|
|
8
|
+
* @property {number} index - The position within the Bitstring Status List that corresponds
|
|
9
|
+
* to the credential's status.
|
|
10
|
+
* @property {string} [purpose] - (Optional) The intended use or role of this status entry.
|
|
11
|
+
*/
|
|
4
12
|
interface W3CVerifiableDocumentConfig {
|
|
5
13
|
url: string;
|
|
6
14
|
index: number;
|
|
7
15
|
purpose?: string;
|
|
8
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Configuration for W3C Transferable Records, including blockchain details and token registry information.
|
|
19
|
+
* @property {string} chain - The name of the blockchain network (e.g., "Ethereum", "Polygon").
|
|
20
|
+
* @property {number} chainId - The unique identifier of the blockchain network.
|
|
21
|
+
* @property {string} tokenRegistry - The smart contract address of the token registry.
|
|
22
|
+
* @property {string} rpcProviderUrl - The RPC endpoint URL for interacting with the blockchain.
|
|
23
|
+
*/
|
|
9
24
|
interface W3CTransferableRecordsConfig {
|
|
10
25
|
chain: string;
|
|
11
26
|
chainId: number;
|
|
12
27
|
tokenRegistry: string;
|
|
13
28
|
rpcProviderUrl: string;
|
|
14
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Configuration for the rendering method used in a Verifiable Credential document.
|
|
32
|
+
* @property {string} id - A unique identifier for the rendering method, typically a URL or URI.
|
|
33
|
+
* @property {string} type - The type of the renderer, which specifies the method of rendering (e.g., 'EMBEDDED_RENDERER').
|
|
34
|
+
* @property {string} templateName - The name of the template to be used for rendering, e.g., 'BILL_OF_LADING'.
|
|
35
|
+
*/
|
|
15
36
|
interface RenderMethod {
|
|
16
37
|
id: string;
|
|
17
38
|
type: string;
|
|
18
39
|
templateName: string;
|
|
19
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Main class responsible for building, configuring, and signing documents with credential statuses.
|
|
43
|
+
*/
|
|
20
44
|
declare class DocumentBuilder {
|
|
21
45
|
private document;
|
|
22
46
|
private documentType;
|
|
@@ -25,6 +49,11 @@ declare class DocumentBuilder {
|
|
|
25
49
|
private rpcProviderUrl;
|
|
26
50
|
private requiredFields;
|
|
27
51
|
private isSigned;
|
|
52
|
+
/**
|
|
53
|
+
* Constructor to initialize the document builder.
|
|
54
|
+
* @param {Partial<VerifiableCredential>} input - The input document.
|
|
55
|
+
* @param {string} [documentType] - The type of the document (default is "w3c").
|
|
56
|
+
*/
|
|
28
57
|
constructor(input: Partial<VerifiableCredential>, documentType?: string);
|
|
29
58
|
credentialSubject(subject: Partial<VerifiableCredential>): this;
|
|
30
59
|
credentialStatus(config: W3CTransferableRecordsConfig | W3CVerifiableDocumentConfig): this;
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts a message using the ChaCha20 encryption algorithm with a given key and nonce.
|
|
3
|
+
*
|
|
4
|
+
* This function takes a plaintext message, converts it to a buffer, and encrypts it using
|
|
5
|
+
* the ChaCha20 stream cipher. The encryption key is processed to ensure it's 32 bytes in length,
|
|
6
|
+
* and the nonce (initialization vector) is either provided or generated as 12 bytes.
|
|
7
|
+
* @param {string} message - The plaintext message to be encrypted.
|
|
8
|
+
* @param {string} key - The encryption key, which will be processed into a 32-byte key.
|
|
9
|
+
* @param {string} [nonce] - (Optional) A 12-byte nonce to be used for the encryption. If not provided, one will be generated.
|
|
10
|
+
* @returns {string} - The encrypted message in base64 format.
|
|
11
|
+
* @throws {Error} - Throws if the encryption process encounters any issues.
|
|
12
|
+
*/
|
|
1
13
|
declare function encrypt(message: string, key: string, nonce?: string): string;
|
|
2
14
|
|
|
3
15
|
export { encrypt };
|
|
@@ -19,6 +19,11 @@ interface TitleEscrowVersionParams {
|
|
|
19
19
|
versionInterface: string;
|
|
20
20
|
provider: Provider | ethers.Provider;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* To provide (tokenRegistryAddress and tokenId) or (titleEscrowAddress)
|
|
24
|
+
* @param {TitleEscrowVersionParams} params - TitleEscrowVersionParams
|
|
25
|
+
* @returns {Promise<boolean>} - return true if titleEscrow matches supportInterface
|
|
26
|
+
*/
|
|
22
27
|
declare const isTitleEscrowVersion: ({ tokenRegistryAddress, tokenId, titleEscrowAddress, versionInterface, provider, }: TitleEscrowVersionParams) => Promise<boolean>;
|
|
23
28
|
declare const fetchEndorsementChain: (tokenRegistryAddress: string, tokenId: string, provider: Provider | ethers.Provider, keyId?: string) => Promise<EndorsementChain>;
|
|
24
29
|
|
|
@@ -6,9 +6,30 @@ type VerificationBuilderOptions = {
|
|
|
6
6
|
documentLoader?: DocumentLoader;
|
|
7
7
|
};
|
|
8
8
|
interface VerifyDocumentParams {
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated
|
|
11
|
+
* Use { rpcProviderUrl?: string, documentLoader?: DocumentLoader } object instead
|
|
12
|
+
*/
|
|
9
13
|
(document: DocumentsToVerify | SignedVerifiableCredential, options: string): Promise<VerificationFragment[]>;
|
|
10
14
|
(document: DocumentsToVerify | SignedVerifiableCredential, options?: VerificationBuilderOptions): Promise<VerificationFragment[]>;
|
|
11
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Asynchronously verifies a document (OpenAttestation or W3C Verifiable Credential) using a specified Ethereum-compatible JSON-RPC provider.
|
|
18
|
+
*
|
|
19
|
+
* This function builds a verification process that can handle both OpenAttestation documents and W3C Verifiable Credentials.
|
|
20
|
+
* For OpenAttestation, it uses OpenAttestation's verifiers and DID identity proof. For W3C Verifiable Credentials,
|
|
21
|
+
* it verifies signatures, credential status, and issuer identity.
|
|
22
|
+
*
|
|
23
|
+
* The function takes an Ethereum-compatible JSON-RPC provider URL, which allows the user to specify the network
|
|
24
|
+
* (e.g., Ethereum, Polygon) for DID resolution and verification tasks.
|
|
25
|
+
* @param {DocumentsToVerify | SignedVerifiableCredential} document - The document to be verified, either an OpenAttestation document or a W3C Verifiable Credential.
|
|
26
|
+
* @param {VerificationBuilderOptions} options - The options object containing the provider URL and document loader.
|
|
27
|
+
* @param {string} options.rpcProviderUrl - The Ethereum-compatible JSON-RPC provider URL (e.g., Infura, Alchemy, Polygon, etc.) to resolve DIDs and verify credentials.
|
|
28
|
+
* @param {DocumentLoader} options.documentLoader - The document loader to be used for loading JSON-LD contexts.
|
|
29
|
+
* @returns {Promise<VerificationFragment[]>} - A promise that resolves to an array of verification fragments,
|
|
30
|
+
* detailing the results of various verification checks such as
|
|
31
|
+
* signature integrity, credential status, issuer identity, etc.
|
|
32
|
+
*/
|
|
12
33
|
declare const verifyDocument: VerifyDocumentParams;
|
|
13
34
|
|
|
14
35
|
export { verifyDocument };
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { v2, v3 } from '@tradetrust-tt/tradetrust';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Asynchronously verifies the signature of an OpenAttestation wrapped document.
|
|
5
|
+
*
|
|
6
|
+
* This function checks if the provided document is of type v2, v3, or v4,
|
|
7
|
+
* and then verifies its signature for validity. It returns a boolean indicating
|
|
8
|
+
* whether the signature is valid. If the document type is not recognized,
|
|
9
|
+
* it will return false.
|
|
10
|
+
* @param {v2.WrappedDocument | v3.WrappedDocument} document - The OpenAttestation document to be verified.
|
|
11
|
+
* @returns {Promise<boolean>} - A promise that resolves to `true` if the document's signature is valid,
|
|
12
|
+
* and `false` if the document type is not recognized or if the signature is invalid.
|
|
13
|
+
*/
|
|
3
14
|
declare const verifyOASignature: (document: v2.WrappedDocument | v3.WrappedDocument) => Promise<boolean>;
|
|
4
15
|
|
|
5
16
|
export { verifyOASignature };
|
|
@@ -1,9 +1,50 @@
|
|
|
1
1
|
import { OpenAttestationDocument, WrappedDocument, v2 } from '@tradetrust-tt/tradetrust';
|
|
2
2
|
export { __unsafe__use__it__at__your__own__risks__wrapDocument as wrapOADocumentV3, __unsafe__use__it__at__your__own__risks__wrapDocuments as wrapOADocumentsV3 } from '@tradetrust-tt/tradetrust';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Asynchronously wraps a V2 OpenAttestation document.
|
|
6
|
+
*
|
|
7
|
+
* This function takes a OpenAttestation document and wraps it using the OpenAttestation
|
|
8
|
+
* library's `wrapOADocument` function. The function will throw any errors encountered during
|
|
9
|
+
* the wrapping process, as handled by the OpenAttestation library.
|
|
10
|
+
* @param {v2.OpenAttestationDocument} document - The OpenAttestation document to be wrapped.
|
|
11
|
+
* @returns {Promise<v2.WrappedDocument>} - A promise that resolves to the wrapped document.
|
|
12
|
+
* @throws {Error} - Any errors thrown by the `wrapOADocument` function will propagate naturally.
|
|
13
|
+
*/
|
|
4
14
|
declare const wrapOADocumentV2: <T extends v2.OpenAttestationDocument>(document: T) => Promise<v2.WrappedDocument<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* Asynchronously wraps multiple V2 OpenAttestation documents.
|
|
17
|
+
*
|
|
18
|
+
* Similar to the `wrapOADocumentV2` function, this function takes an array of OpenAttestation
|
|
19
|
+
* documents and wraps them using the OpenAttestation library's `wrapOADocuments` function. The
|
|
20
|
+
* function will throw any errors encountered during the wrapping process, as handled by the
|
|
21
|
+
* OpenAttestation library.
|
|
22
|
+
* @param {v2.OpenAttestationDocument[]} documents - The OpenAttestation documents to be wrapped.
|
|
23
|
+
* @returns {Promise<v2.WrappedDocument[]>} - A promise that resolves to the wrapped documents.
|
|
24
|
+
* @throws {Error} - Any errors thrown by the `wrapOADocuments` function will propagate naturally.
|
|
25
|
+
*/
|
|
5
26
|
declare const wrapOADocumentsV2: <T extends v2.OpenAttestationDocument>(documents: T[]) => Promise<v2.WrappedDocument<T>[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Asynchronously wraps a v2 / v3 OpenAttestation document.
|
|
29
|
+
*
|
|
30
|
+
* This function takes an OpenAttestation document and validates its version before wrapping it
|
|
31
|
+
* using the OpenAttestation library's `wrapOADocument` function. The function will throw any errors
|
|
32
|
+
* encountered during the wrapping process, as handled by the OpenAttestation library.
|
|
33
|
+
* @param {OpenAttestationDocument} document - The OpenAttestation document to be wrapped.
|
|
34
|
+
* @returns {Promise<WrappedDocument>} - A promise that resolves to the wrapped document.
|
|
35
|
+
* @throws {Error} - Any errors thrown by the `wrapOADocument` function will propagate naturally.
|
|
36
|
+
*/
|
|
6
37
|
declare function wrapOADocument<T extends OpenAttestationDocument>(document: T): Promise<WrappedDocument<T>>;
|
|
38
|
+
/**
|
|
39
|
+
* Asynchronously wraps multiple v2 / v3 OpenAttestation documents.
|
|
40
|
+
*
|
|
41
|
+
* This function takes an array of OpenAttestation documents and validates their versions before wrapping them
|
|
42
|
+
* using the OpenAttestation library's `wrapOADocuments` function. The function will throw any errors
|
|
43
|
+
* encountered during the wrapping process, as handled by the OpenAttestation library.
|
|
44
|
+
* @param {OpenAttestationDocument[]} documents - The OpenAttestation documents to be wrapped.
|
|
45
|
+
* @returns {Promise<WrappedDocument[]>} - A promise that resolves to the wrapped documents.
|
|
46
|
+
* @throws {Error} - Any errors thrown by the `wrapOADocuments` function will propagate naturally.
|
|
47
|
+
*/
|
|
7
48
|
declare function wrapOADocuments<T extends OpenAttestationDocument>(documents: T[]): Promise<WrappedDocument<T>[]>;
|
|
8
49
|
|
|
9
50
|
export { wrapOADocument, wrapOADocumentV2, wrapOADocuments, wrapOADocumentsV2 };
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string into a Uint8Array.
|
|
3
|
+
*
|
|
4
|
+
* This function takes a string input and uses the `Uint8Array` API to encode it into a
|
|
5
|
+
* Uint8Array, which is suitable for binary operations like encryption.
|
|
6
|
+
* @param {string} str - The string to be converted into a Uint8Array.
|
|
7
|
+
* @returns {Uint8Array} - The encoded Uint8Array representation of the input string.
|
|
8
|
+
*/
|
|
1
9
|
declare function stringToUint8Array(str: string): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Generates a 32-byte key by hashing the input string.
|
|
12
|
+
*
|
|
13
|
+
* This function uses the SHAKE256 hash function to generate a 128-bit (32-byte) key
|
|
14
|
+
* from the given input string. SHAKE256 is a cryptographic hash function that produces
|
|
15
|
+
* variable-length output.
|
|
16
|
+
* @param {string} input - The input string to be hashed into a 32-byte key.
|
|
17
|
+
* @returns {string} - A 32-byte hash of the input string, suitable for use as an encryption key.
|
|
18
|
+
*/
|
|
2
19
|
declare function generate32ByteKey(input: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Generates a 12-byte nonce by hashing the input string.
|
|
22
|
+
*
|
|
23
|
+
* This function uses the SHAKE256 hash function to generate a 48-bit (12-byte) nonce
|
|
24
|
+
* from the given input string. The nonce is used as an initialization vector in encryption.
|
|
25
|
+
* @param {string} input - The input string to be hashed into a 12-byte nonce.
|
|
26
|
+
* @returns {string} - A 12-byte hash of the input string, suitable for use as a nonce.
|
|
27
|
+
*/
|
|
3
28
|
declare function generate12ByteNonce(input: string): string;
|
|
4
29
|
|
|
5
30
|
export { generate12ByteNonce, generate32ByteKey, stringToUint8Array };
|
package/dist/types/w3c/sign.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { RawVerifiableCredential, SigningResult } from '@trustvc/w3c-vc';
|
|
2
2
|
import { PrivateKeyPair } from '@trustvc/w3c-issuer';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Signs a W3C Verifiable Credential using the provided cryptographic suite and key pair.
|
|
6
|
+
* @param {RawVerifiableCredential} credential - The verifiable credential object that needs to be signed.
|
|
7
|
+
* @param {PrivateKeyPair} keyPair - The private and public key pair used for signing the credential.
|
|
8
|
+
* @param {string} [cryptoSuite='BbsBlsSignature2020'] - The cryptographic suite to be used for signing (default is 'BbsBlsSignature2020').
|
|
9
|
+
* @returns {Promise<SigningResult>} A promise that resolves to the result of the signing operation, which includes the signed credential.
|
|
10
|
+
*/
|
|
4
11
|
declare const signW3C: (credential: RawVerifiableCredential, keyPair: PrivateKeyPair, cryptoSuite?: string) => Promise<SigningResult>;
|
|
5
12
|
|
|
6
13
|
export { signW3C };
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { SignedVerifiableCredential, DocumentLoader, VerificationResult } from '@trustvc/w3c-vc';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Verifies the signature of a W3C Verifiable Credential.
|
|
5
|
+
* @param {SignedVerifiableCredential} credential - The signed verifiable credential that needs to be verified.
|
|
6
|
+
* @param {object} options - Optional value
|
|
7
|
+
* @param {DocumentLoader} options.documentLoader - The document loader to be used for loading JSON-LD contexts / did.
|
|
8
|
+
* @returns {Promise<VerificationResult>} A promise that resolves to the verification result, indicating whether the credential is valid.
|
|
9
|
+
*/
|
|
3
10
|
declare const verifyW3CSignature: (credential: SignedVerifiableCredential, options?: {
|
|
4
11
|
documentLoader?: DocumentLoader;
|
|
5
12
|
}) => Promise<VerificationResult>;
|