@trustvc/trustvc 1.2.2 → 1.2.3

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.
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ var openAttestation = require('../../open-attestation');
4
+ var fragments = require('../../verify/fragments');
5
+ var vc = require('../../w3c/vc');
6
+ var supportedChains = require('../supportedChains');
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ const getTransferableRecordsCredentialStatus = /* @__PURE__ */ __name((document) => {
11
+ return [
12
+ document?.credentialStatus
13
+ ].flat()?.[0];
14
+ }, "getTransferableRecordsCredentialStatus");
15
+ const isTransferableRecord = /* @__PURE__ */ __name((document) => {
16
+ let isTransferableAssetVal = false;
17
+ if (vc.isSignedDocument(document)) {
18
+ const credentialStatus = getTransferableRecordsCredentialStatus(document);
19
+ isTransferableAssetVal = credentialStatus?.type === fragments.TRANSFERABLE_RECORDS_TYPE;
20
+ } else {
21
+ isTransferableAssetVal = openAttestation.isTransferableAsset(document);
22
+ }
23
+ return isTransferableAssetVal;
24
+ }, "isTransferableRecord");
25
+ const getTokenRegistryAddress = /* @__PURE__ */ __name((document) => {
26
+ let issuerAddress = "";
27
+ if (vc.isSignedDocument(document)) {
28
+ const credentialStatus = getTransferableRecordsCredentialStatus(document);
29
+ issuerAddress = credentialStatus?.tokenRegistry;
30
+ } else {
31
+ issuerAddress = openAttestation.getIssuerAddress(document);
32
+ }
33
+ return issuerAddress instanceof Array ? issuerAddress[0] : issuerAddress;
34
+ }, "getTokenRegistryAddress");
35
+ const getTokenId = /* @__PURE__ */ __name((document) => {
36
+ let tokenId = "";
37
+ if (vc.isSignedDocument(document)) {
38
+ const credentialStatus = getTransferableRecordsCredentialStatus(document);
39
+ tokenId = credentialStatus?.tokenId;
40
+ } else {
41
+ tokenId = openAttestation.getAssetId(document);
42
+ }
43
+ return tokenId && `0x${tokenId}`;
44
+ }, "getTokenId");
45
+ function processOAChainId(document) {
46
+ if (document.network?.chainId) {
47
+ const chainId = parseInt(document.network.chainId, 10);
48
+ if (Object.values(supportedChains.CHAIN_ID).map(Number).includes(chainId)) {
49
+ return chainId;
50
+ }
51
+ throw new Error(`Chain ID ${chainId} is not supported`);
52
+ }
53
+ console.warn(
54
+ "You are using an older version of Open-Attestation Document, to use the auto network feature, please use an updated version. Otherwise, please make sure that you select the correct network."
55
+ );
56
+ return void 0;
57
+ }
58
+ __name(processOAChainId, "processOAChainId");
59
+ const getChainId = /* @__PURE__ */ __name((document) => {
60
+ if (vc.isSignedDocument(document)) {
61
+ const credentialStatus = getTransferableRecordsCredentialStatus(document);
62
+ return credentialStatus?.tokenNetwork?.chainId;
63
+ } else if (openAttestation.isWrappedV2Document(document)) {
64
+ const documentData = openAttestation.getDataV2(document);
65
+ const identityProofType = documentData?.issuers?.[0]?.identityProof?.type;
66
+ if (identityProofType === "DNS-DID" || identityProofType === "DID") return void 0;
67
+ return processOAChainId(documentData);
68
+ } else if (openAttestation.isWrappedV3Document(document)) {
69
+ const identityProofType = document?.openAttestationMetadata?.identityProof?.type;
70
+ if (identityProofType === "DNS-DID" || identityProofType === "DID") return void 0;
71
+ return processOAChainId(document);
72
+ } else {
73
+ return void 0;
74
+ }
75
+ }, "getChainId");
76
+
77
+ exports.getChainId = getChainId;
78
+ exports.getTokenId = getTokenId;
79
+ exports.getTokenRegistryAddress = getTokenRegistryAddress;
80
+ exports.getTransferableRecordsCredentialStatus = getTransferableRecordsCredentialStatus;
81
+ exports.isTransferableRecord = isTransferableRecord;
@@ -5,6 +5,7 @@ var network = require('./network');
5
5
  var stringUtils = require('./stringUtils');
6
6
  var supportedChains = require('./supportedChains');
7
7
  var errorMessages = require('./errorMessages');
8
+ var documents = require('./documents');
8
9
 
9
10
 
10
11
 
@@ -38,3 +39,9 @@ Object.keys(errorMessages).forEach(function (k) {
38
39
  get: function () { return errorMessages[k]; }
39
40
  });
40
41
  });
42
+ Object.keys(documents).forEach(function (k) {
43
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
44
+ enumerable: true,
45
+ get: function () { return documents[k]; }
46
+ });
47
+ });
@@ -0,0 +1,75 @@
1
+ import { isTransferableAsset, getIssuerAddress, getAssetId, isWrappedV2Document, getDataV2, isWrappedV3Document } from '../../open-attestation';
2
+ import { TRANSFERABLE_RECORDS_TYPE } from '../../verify/fragments';
3
+ import { isSignedDocument } from '../../w3c/vc';
4
+ import { CHAIN_ID } from '../supportedChains';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ const getTransferableRecordsCredentialStatus = /* @__PURE__ */ __name((document) => {
9
+ return [
10
+ document?.credentialStatus
11
+ ].flat()?.[0];
12
+ }, "getTransferableRecordsCredentialStatus");
13
+ const isTransferableRecord = /* @__PURE__ */ __name((document) => {
14
+ let isTransferableAssetVal = false;
15
+ if (isSignedDocument(document)) {
16
+ const credentialStatus = getTransferableRecordsCredentialStatus(document);
17
+ isTransferableAssetVal = credentialStatus?.type === TRANSFERABLE_RECORDS_TYPE;
18
+ } else {
19
+ isTransferableAssetVal = isTransferableAsset(document);
20
+ }
21
+ return isTransferableAssetVal;
22
+ }, "isTransferableRecord");
23
+ const getTokenRegistryAddress = /* @__PURE__ */ __name((document) => {
24
+ let issuerAddress = "";
25
+ if (isSignedDocument(document)) {
26
+ const credentialStatus = getTransferableRecordsCredentialStatus(document);
27
+ issuerAddress = credentialStatus?.tokenRegistry;
28
+ } else {
29
+ issuerAddress = getIssuerAddress(document);
30
+ }
31
+ return issuerAddress instanceof Array ? issuerAddress[0] : issuerAddress;
32
+ }, "getTokenRegistryAddress");
33
+ const getTokenId = /* @__PURE__ */ __name((document) => {
34
+ let tokenId = "";
35
+ if (isSignedDocument(document)) {
36
+ const credentialStatus = getTransferableRecordsCredentialStatus(document);
37
+ tokenId = credentialStatus?.tokenId;
38
+ } else {
39
+ tokenId = getAssetId(document);
40
+ }
41
+ return tokenId && `0x${tokenId}`;
42
+ }, "getTokenId");
43
+ function processOAChainId(document) {
44
+ if (document.network?.chainId) {
45
+ const chainId = parseInt(document.network.chainId, 10);
46
+ if (Object.values(CHAIN_ID).map(Number).includes(chainId)) {
47
+ return chainId;
48
+ }
49
+ throw new Error(`Chain ID ${chainId} is not supported`);
50
+ }
51
+ console.warn(
52
+ "You are using an older version of Open-Attestation Document, to use the auto network feature, please use an updated version. Otherwise, please make sure that you select the correct network."
53
+ );
54
+ return void 0;
55
+ }
56
+ __name(processOAChainId, "processOAChainId");
57
+ const getChainId = /* @__PURE__ */ __name((document) => {
58
+ if (isSignedDocument(document)) {
59
+ const credentialStatus = getTransferableRecordsCredentialStatus(document);
60
+ return credentialStatus?.tokenNetwork?.chainId;
61
+ } else if (isWrappedV2Document(document)) {
62
+ const documentData = getDataV2(document);
63
+ const identityProofType = documentData?.issuers?.[0]?.identityProof?.type;
64
+ if (identityProofType === "DNS-DID" || identityProofType === "DID") return void 0;
65
+ return processOAChainId(documentData);
66
+ } else if (isWrappedV3Document(document)) {
67
+ const identityProofType = document?.openAttestationMetadata?.identityProof?.type;
68
+ if (identityProofType === "DNS-DID" || identityProofType === "DID") return void 0;
69
+ return processOAChainId(document);
70
+ } else {
71
+ return void 0;
72
+ }
73
+ }, "getChainId");
74
+
75
+ export { getChainId, getTokenId, getTokenRegistryAddress, getTransferableRecordsCredentialStatus, isTransferableRecord };
@@ -3,3 +3,4 @@ export * from './network';
3
3
  export * from './stringUtils';
4
4
  export * from './supportedChains';
5
5
  export * from './errorMessages';
6
+ export * from './documents';
@@ -37,6 +37,7 @@ export { errorMessageHandling, CONSTANTS as errorMessages, interpretFragments }
37
37
  export * from '@tradetrust-tt/tradetrust-utils/constants/network';
38
38
  export { generate12ByteNonce, generate32ByteKey, stringToUint8Array } from './utils/stringUtils/index.js';
39
39
  export * from '@tradetrust-tt/tradetrust-utils/constants/supportedChains';
40
+ export { WrappedOrSignedOpenAttestationDocument, getChainId, getTokenId, getTokenRegistryAddress, getTransferableRecordsCredentialStatus, isTransferableRecord } from './utils/documents/index.js';
40
41
  export * from '@tradetrust-tt/dnsprove';
41
42
  export { OpenAttestationDocument, SUPPORTED_SIGNING_ALGORITHM, SchemaId, SignedWrappedDocument, WrappedDocument, getData as getDataV2, isSchemaValidationError, obfuscateDocument, v2, v3, validateSchema, __unsafe__use__it__at__your__own__risks__wrapDocument as wrapOADocumentV3, __unsafe__use__it__at__your__own__risks__wrapDocuments as wrapOADocumentsV3 } from '@tradetrust-tt/tradetrust';
42
43
  export { DiagnoseError } from '@tradetrust-tt/tradetrust/dist/types/shared/utils';
@@ -0,0 +1,13 @@
1
+ import { WrappedDocument, OpenAttestationDocument } from '@tradetrust-tt/tradetrust';
2
+ import { TransferableRecordsCredentialStatus } from '@trustvc/w3c-credential-status';
3
+ import { SignedVerifiableCredential } from '@trustvc/w3c-vc';
4
+ import { CHAIN_ID } from '@tradetrust-tt/tradetrust-utils/constants/supportedChains';
5
+
6
+ type WrappedOrSignedOpenAttestationDocument = WrappedDocument<OpenAttestationDocument>;
7
+ declare const getTransferableRecordsCredentialStatus: (document: unknown) => TransferableRecordsCredentialStatus;
8
+ declare const isTransferableRecord: (document: WrappedOrSignedOpenAttestationDocument | SignedVerifiableCredential) => boolean;
9
+ declare const getTokenRegistryAddress: (document: WrappedOrSignedOpenAttestationDocument | SignedVerifiableCredential) => string | undefined;
10
+ declare const getTokenId: (document: WrappedOrSignedOpenAttestationDocument | SignedVerifiableCredential) => string;
11
+ declare const getChainId: (document: WrappedOrSignedOpenAttestationDocument | SignedVerifiableCredential) => CHAIN_ID | undefined;
12
+
13
+ export { type WrappedOrSignedOpenAttestationDocument, getChainId, getTokenId, getTokenRegistryAddress, getTransferableRecordsCredentialStatus, isTransferableRecord };
@@ -2,3 +2,7 @@ export { errorMessageHandling, CONSTANTS as errorMessages, interpretFragments }
2
2
  export * from '@tradetrust-tt/tradetrust-utils/constants/network';
3
3
  export { generate12ByteNonce, generate32ByteKey, stringToUint8Array } from './stringUtils/index.js';
4
4
  export * from '@tradetrust-tt/tradetrust-utils/constants/supportedChains';
5
+ export { WrappedOrSignedOpenAttestationDocument, getChainId, getTokenId, getTokenRegistryAddress, getTransferableRecordsCredentialStatus, isTransferableRecord } from './documents/index.js';
6
+ import '@tradetrust-tt/tradetrust';
7
+ import '@trustvc/w3c-credential-status';
8
+ import '@trustvc/w3c-vc';
@@ -1,7 +1,3 @@
1
- import '@tradetrust-tt/tradetrust-utils';
2
- import '@tradetrust-tt/tradetrust-utils/constants/network';
3
- import '@tradetrust-tt/tradetrust-utils/constants/supportedChains';
4
-
5
1
  declare function stringToUint8Array(str: string): Uint8Array;
6
2
  declare function generate32ByteKey(input: string): string;
7
3
  declare function generate12ByteNonce(input: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustvc/trustvc",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "TrustVC library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -12,6 +12,7 @@
12
12
  "test": "npx vitest --run --test-timeout=15000",
13
13
  "type-check": "tsc --noEmit",
14
14
  "lint": "npx eslint . --color --format=table --max-warnings=0",
15
+ "lint:fix": "npx eslint . --fix",
15
16
  "build": "npm run clean && tsup",
16
17
  "clean": "rm -rf dist/",
17
18
  "precommit": "lint-staged",
@@ -113,7 +114,7 @@
113
114
  "@tradetrust-tt/token-registry-v4": "npm:@tradetrust-tt/token-registry@^4.15.1",
114
115
  "@tradetrust-tt/token-registry-v5": "npm:@tradetrust-tt/token-registry@^5.1.1",
115
116
  "@tradetrust-tt/tradetrust": "^6.10.0",
116
- "@tradetrust-tt/tradetrust-utils": "^2.1.2",
117
+ "@tradetrust-tt/tradetrust-utils": "^2.1.4",
117
118
  "@tradetrust-tt/tt-verify": "^9.3.0",
118
119
  "@trustvc/w3c-context": "^1.2.1",
119
120
  "@trustvc/w3c-credential-status": "^1.2.1",