@flarenetwork/flare-periphery-contract-artifacts 0.1.1 → 0.1.2
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/coston/StateConnector/libs/ts/AttestationDefinitionStore.d.ts +68 -0
- package/dist/coston/StateConnector/libs/ts/AttestationDefinitionStore.d.ts.map +1 -0
- package/dist/coston/StateConnector/libs/ts/AttestationDefinitionStore.js +164 -0
- package/dist/coston/StateConnector/libs/ts/AttestationDefinitionStore.js.map +1 -0
- package/dist/coston/StateConnector/libs/ts/AttestationResponse.d.ts +33 -0
- package/dist/coston/StateConnector/libs/ts/AttestationResponse.d.ts.map +1 -0
- package/dist/coston/StateConnector/libs/ts/AttestationResponse.js +30 -0
- package/dist/coston/StateConnector/libs/ts/AttestationResponse.js.map +1 -0
- package/dist/coston/StateConnector/libs/ts/MerkleTree.d.ts +103 -0
- package/dist/coston/StateConnector/libs/ts/MerkleTree.d.ts.map +1 -0
- package/dist/coston/StateConnector/libs/ts/MerkleTree.js +212 -0
- package/dist/coston/StateConnector/libs/ts/MerkleTree.js.map +1 -0
- package/dist/coston/StateConnector/libs/ts/config-types.d.ts +143 -0
- package/dist/coston/StateConnector/libs/ts/config-types.d.ts.map +1 -0
- package/dist/coston/StateConnector/libs/ts/config-types.js +3 -0
- package/dist/coston/StateConnector/libs/ts/config-types.js.map +1 -0
- package/dist/coston/StateConnector/libs/ts/interfaces.d.ts +32 -0
- package/dist/coston/StateConnector/libs/ts/interfaces.d.ts.map +1 -0
- package/dist/coston/StateConnector/libs/ts/interfaces.js +3 -0
- package/dist/coston/StateConnector/libs/ts/interfaces.js.map +1 -0
- package/dist/coston/StateConnector/libs/ts/random.d.ts +9 -0
- package/dist/coston/StateConnector/libs/ts/random.d.ts.map +1 -0
- package/dist/coston/StateConnector/libs/ts/random.js +70 -0
- package/dist/coston/StateConnector/libs/ts/random.js.map +1 -0
- package/dist/coston/StateConnector/libs/ts/utils.d.ts +73 -0
- package/dist/coston/StateConnector/libs/ts/utils.d.ts.map +1 -0
- package/dist/coston/StateConnector/libs/ts/utils.js +282 -0
- package/dist/coston/StateConnector/libs/ts/utils.js.map +1 -0
- package/dist/coston/StateConnector/typescript/AddressValidity.d.ts +91 -0
- package/dist/coston/StateConnector/typescript/AddressValidity.d.ts.map +1 -0
- package/dist/coston/StateConnector/typescript/AddressValidity.js +9 -0
- package/dist/coston/StateConnector/typescript/AddressValidity.js.map +1 -0
- package/dist/coston/StateConnector/typescript/BalanceDecreasingTransaction.d.ts +107 -0
- package/dist/coston/StateConnector/typescript/BalanceDecreasingTransaction.d.ts.map +1 -0
- package/dist/coston/StateConnector/typescript/BalanceDecreasingTransaction.js +9 -0
- package/dist/coston/StateConnector/typescript/BalanceDecreasingTransaction.js.map +1 -0
- package/dist/coston/StateConnector/typescript/ConfirmedBlockHeightExists.d.ts +103 -0
- package/dist/coston/StateConnector/typescript/ConfirmedBlockHeightExists.d.ts.map +1 -0
- package/dist/coston/StateConnector/typescript/ConfirmedBlockHeightExists.js +9 -0
- package/dist/coston/StateConnector/typescript/ConfirmedBlockHeightExists.js.map +1 -0
- package/dist/coston/StateConnector/typescript/EVMTransaction.d.ts +160 -0
- package/dist/coston/StateConnector/typescript/EVMTransaction.d.ts.map +1 -0
- package/dist/coston/StateConnector/typescript/EVMTransaction.js +9 -0
- package/dist/coston/StateConnector/typescript/EVMTransaction.js.map +1 -0
- package/dist/coston/StateConnector/typescript/Payment.d.ts +139 -0
- package/dist/coston/StateConnector/typescript/Payment.d.ts.map +1 -0
- package/dist/coston/StateConnector/typescript/Payment.js +9 -0
- package/dist/coston/StateConnector/typescript/Payment.js.map +1 -0
- package/dist/coston/StateConnector/typescript/ReferencedPaymentNonexistence.d.ts +115 -0
- package/dist/coston/StateConnector/typescript/ReferencedPaymentNonexistence.d.ts.map +1 -0
- package/dist/coston/StateConnector/typescript/ReferencedPaymentNonexistence.js +9 -0
- package/dist/coston/StateConnector/typescript/ReferencedPaymentNonexistence.js.map +1 -0
- package/dist/coston/StateConnector/typescript/TypeTemplate.d.ts +146 -0
- package/dist/coston/StateConnector/typescript/TypeTemplate.d.ts.map +1 -0
- package/dist/coston/StateConnector/typescript/TypeTemplate.js +9 -0
- package/dist/coston/StateConnector/typescript/TypeTemplate.js.map +1 -0
- package/dist/coston/StateConnector/typescript/data-sources/data-sources.d.ts +29 -0
- package/dist/coston/StateConnector/typescript/data-sources/data-sources.d.ts.map +1 -0
- package/dist/coston/StateConnector/typescript/data-sources/data-sources.js +33 -0
- package/dist/coston/StateConnector/typescript/data-sources/data-sources.js.map +1 -0
- package/dist/coston/StateConnector/typescript/index.d.ts +9 -0
- package/dist/coston/StateConnector/typescript/index.d.ts.map +1 -0
- package/dist/coston/StateConnector/typescript/index.js +25 -0
- package/dist/coston/StateConnector/typescript/index.js.map +1 -0
- package/dist/coston/deploys/mapper.js.map +1 -1
- package/dist/coston2/deploys/mapper.js.map +1 -1
- package/dist/flare/deploys/mapper.js.map +1 -1
- package/dist/songbird/deploys/mapper.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ABI definition fields for request, response and proof of an attestation type.
|
|
3
|
+
*/
|
|
4
|
+
export interface ABIDefinitions {
|
|
5
|
+
/**
|
|
6
|
+
* JSON ABI definition for attestation type request
|
|
7
|
+
*/
|
|
8
|
+
requestAbi: any;
|
|
9
|
+
/**
|
|
10
|
+
* JSON ABI definition for attestation type response
|
|
11
|
+
*/
|
|
12
|
+
responseAbi: any;
|
|
13
|
+
/**
|
|
14
|
+
* JSON ABI definition for attestation type proof
|
|
15
|
+
*/
|
|
16
|
+
proofAbi: any;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Metadata for basic and ABI configs for an attestation type.
|
|
20
|
+
*/
|
|
21
|
+
export interface TypeRecord extends ABIDefinitions {
|
|
22
|
+
/**
|
|
23
|
+
* Attestation type name. Must be unique and in PascalCase (also known as UpperCamelCase, hence CamelCase with the first letter capitalized).
|
|
24
|
+
*/
|
|
25
|
+
name: string;
|
|
26
|
+
/**
|
|
27
|
+
* Full comment for the attestation type as provided in the Solidity definition.
|
|
28
|
+
*/
|
|
29
|
+
fullComment: string;
|
|
30
|
+
/**
|
|
31
|
+
* Description of the attestation type. Used also in the generated documentation.
|
|
32
|
+
*/
|
|
33
|
+
description: string;
|
|
34
|
+
/**
|
|
35
|
+
* Comma separated list of supported sources for the attestation type. The strings defining types are community defined.
|
|
36
|
+
* Currently, the following are supported: BTC, DOGE, XRP, ETH
|
|
37
|
+
*/
|
|
38
|
+
supported: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Text describing the attestation type verification rules. In Markdown format.
|
|
41
|
+
*/
|
|
42
|
+
verification: string;
|
|
43
|
+
/**
|
|
44
|
+
* The description of how lowest used timestamp is obtained from the attestation response.
|
|
45
|
+
* Usually a field name.
|
|
46
|
+
*/
|
|
47
|
+
lut: string;
|
|
48
|
+
/**
|
|
49
|
+
* Metadata about the struct describing attestation request.
|
|
50
|
+
*/
|
|
51
|
+
request: StructRecord;
|
|
52
|
+
/**
|
|
53
|
+
* Metadata about the struct describing attestation response.
|
|
54
|
+
*/
|
|
55
|
+
response: StructRecord;
|
|
56
|
+
/**
|
|
57
|
+
* Metadata about the struct describing attestation proof.
|
|
58
|
+
*/
|
|
59
|
+
proof: StructRecord;
|
|
60
|
+
/**
|
|
61
|
+
* Metadata about the struct describing attestation request body.
|
|
62
|
+
*/
|
|
63
|
+
requestBody: StructRecord;
|
|
64
|
+
/**
|
|
65
|
+
* Metadata about the struct describing attestation response body.
|
|
66
|
+
*/
|
|
67
|
+
responseBody: StructRecord;
|
|
68
|
+
/**
|
|
69
|
+
* List of metadata objects describing structs used in attestation request.
|
|
70
|
+
*/
|
|
71
|
+
requestStructs: StructRecord[];
|
|
72
|
+
/**
|
|
73
|
+
* List of metadata objects describing structs used in attestation response.
|
|
74
|
+
*/
|
|
75
|
+
responseStructs: StructRecord[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Metadata for a struct parameter from a Solidity definition of attestation types.
|
|
79
|
+
*/
|
|
80
|
+
export interface ParamRecord {
|
|
81
|
+
/**
|
|
82
|
+
* Field name.
|
|
83
|
+
*/
|
|
84
|
+
name: string;
|
|
85
|
+
/**
|
|
86
|
+
* Field type as defined in Solidity.
|
|
87
|
+
*/
|
|
88
|
+
type: string;
|
|
89
|
+
/**
|
|
90
|
+
* Short field type (omitting position prefixes for structs)
|
|
91
|
+
*/
|
|
92
|
+
typeSimple?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Field description. Possibly multiline.
|
|
95
|
+
*/
|
|
96
|
+
comment: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Metadata for a struct from a Solidity definition of attestation types.
|
|
100
|
+
*/
|
|
101
|
+
export interface StructRecord {
|
|
102
|
+
/**
|
|
103
|
+
* Struct name.
|
|
104
|
+
*/
|
|
105
|
+
name: string;
|
|
106
|
+
/**
|
|
107
|
+
* Full comment for the struct as provided in the Solidity definition.
|
|
108
|
+
*/
|
|
109
|
+
fullComment: string;
|
|
110
|
+
/**
|
|
111
|
+
* Struct description. Possibly multiline, can use Markdown.
|
|
112
|
+
*/
|
|
113
|
+
description: string;
|
|
114
|
+
/**
|
|
115
|
+
* Additional markdown text to be used above the struct fields description in documentation.
|
|
116
|
+
*/
|
|
117
|
+
above?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Additional markdown text to be used below the struct fields description in documentation.
|
|
120
|
+
*/
|
|
121
|
+
below?: string;
|
|
122
|
+
/**
|
|
123
|
+
* List of metadata objects describing struct fields.
|
|
124
|
+
*/
|
|
125
|
+
params: ParamRecord[];
|
|
126
|
+
}
|
|
127
|
+
export interface DataSource {
|
|
128
|
+
name: string;
|
|
129
|
+
description: string;
|
|
130
|
+
}
|
|
131
|
+
export interface Protocol {
|
|
132
|
+
name: string;
|
|
133
|
+
description: string;
|
|
134
|
+
}
|
|
135
|
+
export interface AttestationTypeProtocolSupport {
|
|
136
|
+
attestationType: string;
|
|
137
|
+
supportedDataSources: string[];
|
|
138
|
+
}
|
|
139
|
+
export interface ProtocolSupport {
|
|
140
|
+
protocol: string;
|
|
141
|
+
supported: AttestationTypeProtocolSupport[];
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=config-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-types.d.ts","sourceRoot":"","sources":["../../../../../coston/StateConnector/libs/ts/config-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,UAAU,EAAE,GAAG,CAAC;IAChB;;OAEG;IACH,WAAW,EAAE,GAAG,CAAC;IACjB;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,cAAc;IAC9C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IACtB;;OAEG;IACH,QAAQ,EAAE,YAAY,CAAC;IACvB;;OAEG;IACH,KAAK,EAAE,YAAY,CAAC;IACpB;;OAEG;IACH,WAAW,EAAE,YAAY,CAAC;IAC1B;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,cAAc,EAAE,YAAY,EAAE,CAAC;IAC/B;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,MAAM,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,8BAA8B;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAClC;AACD,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,8BAA8B,EAAE,CAAC;CAC/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-types.js","sourceRoot":"","sources":["../../../../../coston/StateConnector/libs/ts/config-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic interface for the request of an attestation request.
|
|
3
|
+
*/
|
|
4
|
+
export interface ARBase {
|
|
5
|
+
attestationType: string;
|
|
6
|
+
sourceId: string;
|
|
7
|
+
messageIntegrityCode?: string;
|
|
8
|
+
requestBody: any;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Generic interface for the response of an attestation request.
|
|
12
|
+
*/
|
|
13
|
+
export interface ARESBase {
|
|
14
|
+
attestationType: string;
|
|
15
|
+
sourceId: string;
|
|
16
|
+
votingRound: string;
|
|
17
|
+
lowestUsedTimestamp: string;
|
|
18
|
+
requestBody: any;
|
|
19
|
+
responseBody: any;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generic interface for example data usually randomly generated for testing purposes and examples.
|
|
23
|
+
*/
|
|
24
|
+
export interface ExampleData<RNM, REQ, RES> {
|
|
25
|
+
requestNoMic: RNM;
|
|
26
|
+
request: REQ;
|
|
27
|
+
response: RES;
|
|
28
|
+
messageIntegrityCode: string;
|
|
29
|
+
encodedRequestZeroMic: string;
|
|
30
|
+
encodedRequest: string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../coston/StateConnector/libs/ts/interfaces.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,EAAE,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,GAAG,CAAC;IACjB,YAAY,EAAE,GAAG,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG;IACtC,YAAY,EAAE,GAAG,CAAC;IAClB,OAAO,EAAE,GAAG,CAAC;IACb,QAAQ,EAAE,GAAG,CAAC;IACd,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAc,EAAE,MAAM,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../coston/StateConnector/libs/ts/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function seededRandHex(n: number, seed?: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Helper random value generator for Solidity type values used in in randomized attestation requests or responses.
|
|
4
|
+
* Primarily used for testing
|
|
5
|
+
* @param typeName solidity type (e.g. uint256)
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function randSol(typeName: string, seed?: string): string | boolean;
|
|
9
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../../../coston/StateConnector/libs/ts/random.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,SAAM,UAElD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,MAAM,GAAG,OAAO,CAyDtE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randSol = exports.seededRandHex = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
function seededRandHex(n, seed = "0") {
|
|
6
|
+
return ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(seed)).slice(0, 2 + 2 * n);
|
|
7
|
+
}
|
|
8
|
+
exports.seededRandHex = seededRandHex;
|
|
9
|
+
/**
|
|
10
|
+
* Helper random value generator for Solidity type values used in in randomized attestation requests or responses.
|
|
11
|
+
* Primarily used for testing
|
|
12
|
+
* @param typeName solidity type (e.g. uint256)
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
function randSol(typeName, seed = "0") {
|
|
16
|
+
let match = typeName.match(/^.+(\[(\d*)\])$/);
|
|
17
|
+
if (match) {
|
|
18
|
+
const brackets = match[1];
|
|
19
|
+
const value = parseInt(match[2]);
|
|
20
|
+
const typeOfArray = typeName.slice(0, -brackets.length);
|
|
21
|
+
if (!isNaN(value) || value === 0) {
|
|
22
|
+
return ("[" +
|
|
23
|
+
Array(value)
|
|
24
|
+
.fill(0)
|
|
25
|
+
.map(() => randSol(typeOfArray, seed))
|
|
26
|
+
.join(", ") +
|
|
27
|
+
"]");
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const length = 3; // fixed length
|
|
31
|
+
return ("[" +
|
|
32
|
+
Array(length)
|
|
33
|
+
.fill(0)
|
|
34
|
+
.map(() => randSol(typeOfArray, seed))
|
|
35
|
+
.join(", ") +
|
|
36
|
+
"]");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
match = typeName.match(/^uint(\d+)$/);
|
|
40
|
+
if (match) {
|
|
41
|
+
return BigInt(seededRandHex(parseInt(match[1]) / 8, seed)).toString();
|
|
42
|
+
}
|
|
43
|
+
match = typeName.match(/^int(\d+)$/);
|
|
44
|
+
if (match) {
|
|
45
|
+
const val = seededRandHex(parseInt(match[1]) / 8, seed);
|
|
46
|
+
return BigInt("0x0" + val.slice(3)).toString();
|
|
47
|
+
}
|
|
48
|
+
if (typeName.match(/^bool$/)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
match = typeName.match(/^bytes(\d+)$/);
|
|
52
|
+
if (match) {
|
|
53
|
+
return seededRandHex(parseInt(match[1]), seed);
|
|
54
|
+
}
|
|
55
|
+
if (typeName.match(/^address$/)) {
|
|
56
|
+
return seededRandHex(20, seed);
|
|
57
|
+
}
|
|
58
|
+
if (typeName.match(/^string$/)) {
|
|
59
|
+
return "Random string";
|
|
60
|
+
}
|
|
61
|
+
if (typeName.match(/^byte$/)) {
|
|
62
|
+
return seededRandHex(1, seed);
|
|
63
|
+
}
|
|
64
|
+
if (typeName.match(/^bytes$/)) {
|
|
65
|
+
return seededRandHex(30, seed);
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`Unsupported type ${typeName}`);
|
|
68
|
+
}
|
|
69
|
+
exports.randSol = randSol;
|
|
70
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../../coston/StateConnector/libs/ts/random.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { TypeRecord } from "./config-types";
|
|
2
|
+
/**
|
|
3
|
+
* ABIFragment is a subset of ethers ABIFragment. It is used to define the ABI fragments
|
|
4
|
+
*/
|
|
5
|
+
export interface ABIFragment {
|
|
6
|
+
components?: ABIFragment[];
|
|
7
|
+
internalType: string;
|
|
8
|
+
name: string;
|
|
9
|
+
type: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_ATTESTATION_TYPE_CONFIGS_PATH = "./node_modules/@flarenetwork/flare-periphery-contract-artifacts/coston/StateConnector/configs/";
|
|
12
|
+
export declare const MIC_SALT = "Flare";
|
|
13
|
+
export declare const ZERO_BYTES_32: string;
|
|
14
|
+
export declare const ZERO_BYTES_20: string;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the type is one of the supported Solidity type names.
|
|
17
|
+
* Note: the checks for supported numbers N in 'intN', 'uintN' and 'bytesN' is not implemented. The function is safe only under assumption
|
|
18
|
+
* that the correct types supported by the Solidity compiler are used.
|
|
19
|
+
* @param type
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare function isSupportedBasicSolidityType(type: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Encodes attestation type name or source id as a 32-byte hex string.
|
|
25
|
+
* It takes the UTF-8 bytes of the name and pads them with zeros to 32 bytes.
|
|
26
|
+
* @param attestationTypeName
|
|
27
|
+
* @returns '0x'-prefixed hex string representing 32-bytes
|
|
28
|
+
*/
|
|
29
|
+
export declare function encodeAttestationName(attestationTypeName: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Decodes attestation type name or source id from a 32-byte hex string.
|
|
32
|
+
* @param encoded Should be a '0x'-prefixed hex string representing exactly 32-bytes.
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
export declare function decodeAttestationName(encoded: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Given a ABI decoded object (with tuples) based on the provided JSON ABI definition,
|
|
38
|
+
* it creates a possibly nested Javascript object compatible with the ABI definitions.
|
|
39
|
+
* The function assumes that the decoded objects matches the ABI. If this is not the case,
|
|
40
|
+
* function may behave in strange ways.
|
|
41
|
+
* This is auxiliary function not intended to be used directly.
|
|
42
|
+
* @param decoded
|
|
43
|
+
* @param abi
|
|
44
|
+
* @param ignoreArray parameter for recursion call when handling of arrays are needed.
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
export declare function remapABIParsedToObjects(decoded: any, abi: ABIFragment, ignoreArray?: boolean): any;
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether the struct objects are deep equal. Objects should match the ABI definition.
|
|
50
|
+
* @param struct1
|
|
51
|
+
* @param struct2
|
|
52
|
+
* @param abi
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
export declare function structsDeepEqual(struct1: any, struct2: any, abi: ABIFragment): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Loader of the attestation type definition configs
|
|
58
|
+
* @returns a map from attestation types to definition configs
|
|
59
|
+
*/
|
|
60
|
+
export declare function readAttestationTypeConfigs(configsPath?: string): Map<string, TypeRecord>;
|
|
61
|
+
/**
|
|
62
|
+
* Helper function serializing bigints to strings recursively.
|
|
63
|
+
* @param obj
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
export declare function serializeBigInts(obj: any): any;
|
|
67
|
+
/**
|
|
68
|
+
* Find the package root than contains the directory.
|
|
69
|
+
* @param moduleDir the directory of a module, typically use `__dirname`
|
|
70
|
+
* @returns the directory of the modules's package root.
|
|
71
|
+
*/
|
|
72
|
+
export declare function findPackageRoot(moduleDir: string): string;
|
|
73
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../coston/StateConnector/libs/ts/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,UAAU,CAAC,EAAE,WAAW,EAAE,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,qCAAqC,mGAAmG,CAAA;AACrJ,eAAO,MAAM,QAAQ,UAAU,CAAC;AAChC,eAAO,MAAM,aAAa,QAAgC,CAAC;AAC3D,eAAO,MAAM,aAAa,QAAgC,CAAC;AA+C3D;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAUlE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,mBAAmB,EAAE,MAAM,UAYhE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,UAUpD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,WAAW,UAAQ,GAAG,GAAG,CA8BhG;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CA2DtF;AACD;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,SAAwC,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAQvH;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,OAOxC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,UAiBhD"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.findPackageRoot = exports.serializeBigInts = exports.readAttestationTypeConfigs = exports.structsDeepEqual = exports.remapABIParsedToObjects = exports.decodeAttestationName = exports.encodeAttestationName = exports.isSupportedBasicSolidityType = exports.ZERO_BYTES_20 = exports.ZERO_BYTES_32 = exports.MIC_SALT = exports.DEFAULT_ATTESTATION_TYPE_CONFIGS_PATH = void 0;
|
|
27
|
+
const ethers_1 = require("ethers");
|
|
28
|
+
const fs_1 = require("fs");
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
exports.DEFAULT_ATTESTATION_TYPE_CONFIGS_PATH = "./node_modules/@flarenetwork/flare-periphery-contract-artifacts/coston/StateConnector/configs/";
|
|
31
|
+
exports.MIC_SALT = "Flare";
|
|
32
|
+
exports.ZERO_BYTES_32 = ethers_1.ethers.zeroPadBytes("0x", 32);
|
|
33
|
+
exports.ZERO_BYTES_20 = ethers_1.ethers.zeroPadBytes("0x", 20);
|
|
34
|
+
/**
|
|
35
|
+
* Compares values of Solidity elementary types when represented in JSON.
|
|
36
|
+
* Checks the consistency of the types and the values.
|
|
37
|
+
* @param val1
|
|
38
|
+
* @param val2
|
|
39
|
+
* @param type
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
function compareElementaryTypes(val1, val2, type) {
|
|
43
|
+
if (type.match(/^u?int\d+$/)) {
|
|
44
|
+
// Input values could be number, BigInt or string representing decimal or hex (0x-prefixed).
|
|
45
|
+
if (typeof val1 === "number" || typeof val1 === "bigint" || typeof val1 === "string") {
|
|
46
|
+
// throws if the value is not parsable as a BigInt
|
|
47
|
+
return BigInt(val1) === BigInt(val2);
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Invalid values for type '${type}': ${val1}, ${val2}`);
|
|
50
|
+
}
|
|
51
|
+
if (type.match(/^bool$/)) {
|
|
52
|
+
// values must be true or false
|
|
53
|
+
if ((val1 === true || val1 === false) && (val2 === true || val2 === false)) {
|
|
54
|
+
return val1 === val2;
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`Invalid values for type '${type}': ${val1}, ${val2}`);
|
|
57
|
+
}
|
|
58
|
+
if (type.match(/^bytes\d*$/) || type.match(/^byte$/) || type.match(/^address$/)) {
|
|
59
|
+
// Input values must be be string or hex (0x-prefixed)
|
|
60
|
+
if (typeof val1 === "string" && typeof val2 === "string") {
|
|
61
|
+
const lower1 = val1.toLowerCase();
|
|
62
|
+
const lower2 = val2.toLowerCase();
|
|
63
|
+
if (/^0x[0-9a-f]+$/i.test(lower1) && /^0x[0-9a-f]+$/i.test(lower2)) {
|
|
64
|
+
return lower1 === lower2;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`Invalid values for type '${type}': '${val1}', '${val2}'`);
|
|
68
|
+
}
|
|
69
|
+
if (type.match(/^string$/)) {
|
|
70
|
+
// Input values must be string
|
|
71
|
+
if (typeof val1 === "string" && typeof val2 === "string") {
|
|
72
|
+
return val1 === val2;
|
|
73
|
+
}
|
|
74
|
+
throw new Error(`Invalid values for type '${type}': '${val1}', '${val2}'`);
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`Unknown or unsupported type '${type}'`);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Checks if the type is one of the supported Solidity type names.
|
|
80
|
+
* Note: the checks for supported numbers N in 'intN', 'uintN' and 'bytesN' is not implemented. The function is safe only under assumption
|
|
81
|
+
* that the correct types supported by the Solidity compiler are used.
|
|
82
|
+
* @param type
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
function isSupportedBasicSolidityType(type) {
|
|
86
|
+
//
|
|
87
|
+
return (!!type.match(/^u?int\d+$/) ||
|
|
88
|
+
!!type.match(/^bool$/) ||
|
|
89
|
+
!!type.match(/^bytes\d*$/) ||
|
|
90
|
+
!!type.match(/^byte$/) ||
|
|
91
|
+
!!type.match(/^address$/) ||
|
|
92
|
+
!!type.match(/^string$/));
|
|
93
|
+
}
|
|
94
|
+
exports.isSupportedBasicSolidityType = isSupportedBasicSolidityType;
|
|
95
|
+
/**
|
|
96
|
+
* Encodes attestation type name or source id as a 32-byte hex string.
|
|
97
|
+
* It takes the UTF-8 bytes of the name and pads them with zeros to 32 bytes.
|
|
98
|
+
* @param attestationTypeName
|
|
99
|
+
* @returns '0x'-prefixed hex string representing 32-bytes
|
|
100
|
+
*/
|
|
101
|
+
function encodeAttestationName(attestationTypeName) {
|
|
102
|
+
if (typeof attestationTypeName !== "string") {
|
|
103
|
+
throw new Error(`Attestation type name must be a string. Provided value ${attestationTypeName}`);
|
|
104
|
+
}
|
|
105
|
+
if (attestationTypeName.startsWith("0x") || attestationTypeName.startsWith("0X")) {
|
|
106
|
+
throw new Error(`Attestation type name must not start with '0x'. Provided value '${attestationTypeName}'. Possible confusion with hex encoding.`);
|
|
107
|
+
}
|
|
108
|
+
const bytes = ethers_1.ethers.toUtf8Bytes(attestationTypeName);
|
|
109
|
+
if (bytes.length > 32) {
|
|
110
|
+
throw new Error(`Attestation type name ${attestationTypeName} is too long`);
|
|
111
|
+
}
|
|
112
|
+
return ethers_1.ethers.zeroPadBytes(bytes, 32);
|
|
113
|
+
}
|
|
114
|
+
exports.encodeAttestationName = encodeAttestationName;
|
|
115
|
+
/**
|
|
116
|
+
* Decodes attestation type name or source id from a 32-byte hex string.
|
|
117
|
+
* @param encoded Should be a '0x'-prefixed hex string representing exactly 32-bytes.
|
|
118
|
+
* @returns
|
|
119
|
+
*/
|
|
120
|
+
function decodeAttestationName(encoded) {
|
|
121
|
+
if (!/^0x[0-9a-fA-F]{64}$/i.test(encoded)) {
|
|
122
|
+
throw new Error("Not a 0x-prefixed 32-byte hex string");
|
|
123
|
+
}
|
|
124
|
+
// strip trailing zeros
|
|
125
|
+
let stripped = encoded.replace(/0+$/, "");
|
|
126
|
+
// if the string is odd-length, add a zero to the end for full bytes
|
|
127
|
+
stripped = stripped.length % 2 == 0 ? stripped : stripped + "0";
|
|
128
|
+
const bytes = ethers_1.ethers.toBeArray(stripped);
|
|
129
|
+
return ethers_1.ethers.toUtf8String(bytes);
|
|
130
|
+
}
|
|
131
|
+
exports.decodeAttestationName = decodeAttestationName;
|
|
132
|
+
/**
|
|
133
|
+
* Given a ABI decoded object (with tuples) based on the provided JSON ABI definition,
|
|
134
|
+
* it creates a possibly nested Javascript object compatible with the ABI definitions.
|
|
135
|
+
* The function assumes that the decoded objects matches the ABI. If this is not the case,
|
|
136
|
+
* function may behave in strange ways.
|
|
137
|
+
* This is auxiliary function not intended to be used directly.
|
|
138
|
+
* @param decoded
|
|
139
|
+
* @param abi
|
|
140
|
+
* @param ignoreArray parameter for recursion call when handling of arrays are needed.
|
|
141
|
+
* @returns
|
|
142
|
+
*/
|
|
143
|
+
function remapABIParsedToObjects(decoded, abi, ignoreArray = false) {
|
|
144
|
+
if (abi.type == "tuple" || (abi.type == "tuple[]" && ignoreArray)) {
|
|
145
|
+
const result = {};
|
|
146
|
+
for (const [index, item] of abi.components.entries()) {
|
|
147
|
+
const key = item.name;
|
|
148
|
+
result[key] = remapABIParsedToObjects(decoded[index], item);
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
if (abi.type == "tuple[]") {
|
|
153
|
+
const result = [];
|
|
154
|
+
for (const item of decoded) {
|
|
155
|
+
result.push(remapABIParsedToObjects(item, abi, true));
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
if (abi.type.match(/^.+(\[(\d*)\])(\[(\d*)\])$/) || abi.type.match(/^.+(\[(\d+)\])$/)) {
|
|
160
|
+
throw new Error(`Nested arrays or fixed length arrays not supported. Type: ${abi.type}`);
|
|
161
|
+
}
|
|
162
|
+
// we assume here we have `type[]` where `type` is one of simple types.
|
|
163
|
+
const match = abi.type.match(/^(.+)\[\]$/);
|
|
164
|
+
if (match && isSupportedBasicSolidityType(match[1])) {
|
|
165
|
+
const result = [];
|
|
166
|
+
for (const item of decoded) {
|
|
167
|
+
result.push(item);
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
return decoded;
|
|
172
|
+
}
|
|
173
|
+
exports.remapABIParsedToObjects = remapABIParsedToObjects;
|
|
174
|
+
/**
|
|
175
|
+
* Checks whether the struct objects are deep equal. Objects should match the ABI definition.
|
|
176
|
+
* @param struct1
|
|
177
|
+
* @param struct2
|
|
178
|
+
* @param abi
|
|
179
|
+
* @returns
|
|
180
|
+
*/
|
|
181
|
+
function structsDeepEqual(struct1, struct2, abi) {
|
|
182
|
+
if (Object.keys(struct1).length !== Object.keys(struct2).length) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
for (const item of abi.components || []) {
|
|
186
|
+
const key = item.name;
|
|
187
|
+
const val1 = struct1[key];
|
|
188
|
+
const val2 = struct2[key];
|
|
189
|
+
if (val1 === undefined || val2 === undefined) {
|
|
190
|
+
throw new Error(`Structs must not have undefined values for ${key}`);
|
|
191
|
+
}
|
|
192
|
+
if (item.type == "tuple") {
|
|
193
|
+
if (!structsDeepEqual(struct1[key], struct2[key], item)) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (item.type == "tuple[]") {
|
|
199
|
+
if (val1.length != val2.length) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
for (let i = 0; i < val1.length; i++) {
|
|
203
|
+
if (!structsDeepEqual(val1[i], val2[i], item)) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (item.components) {
|
|
210
|
+
throw new Error("Components should not appear in non tuple ABI fragments");
|
|
211
|
+
}
|
|
212
|
+
if (item.type.match(/^.+(\[(\d*)\])(\[(\d*)\])$/) || item.type.match(/^.+(\[(\d+)\])$/)) {
|
|
213
|
+
throw new Error(`Nested arrays or fixed length arrays not supported. Type: ${item.type}`);
|
|
214
|
+
}
|
|
215
|
+
// we assume here we have `type[]` where `type` is one of simple types.
|
|
216
|
+
const match = item.type.match(/^(.+)\[\]$/);
|
|
217
|
+
if (match && isSupportedBasicSolidityType(match[1])) {
|
|
218
|
+
if (val1.length !== val2.length) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
for (let i = 0; i < val1.length; i++) {
|
|
222
|
+
if (!compareElementaryTypes(val1[i], val2[i], item.type.slice(0, -2))) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (!compareElementaryTypes(val1, val2, item.type)) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
exports.structsDeepEqual = structsDeepEqual;
|
|
235
|
+
/**
|
|
236
|
+
* Loader of the attestation type definition configs
|
|
237
|
+
* @returns a map from attestation types to definition configs
|
|
238
|
+
*/
|
|
239
|
+
function readAttestationTypeConfigs(configsPath = exports.DEFAULT_ATTESTATION_TYPE_CONFIGS_PATH) {
|
|
240
|
+
const typeRecMap = new Map();
|
|
241
|
+
const files = (0, fs_1.readdirSync)(configsPath);
|
|
242
|
+
files.forEach((fileName) => {
|
|
243
|
+
const name = path.basename(fileName, ".json");
|
|
244
|
+
typeRecMap.set(name, JSON.parse((0, fs_1.readFileSync)(`${configsPath}/${fileName}`, "utf8")));
|
|
245
|
+
});
|
|
246
|
+
return typeRecMap;
|
|
247
|
+
}
|
|
248
|
+
exports.readAttestationTypeConfigs = readAttestationTypeConfigs;
|
|
249
|
+
/**
|
|
250
|
+
* Helper function serializing bigints to strings recursively.
|
|
251
|
+
* @param obj
|
|
252
|
+
* @returns
|
|
253
|
+
*/
|
|
254
|
+
function serializeBigInts(obj) {
|
|
255
|
+
return JSON.parse(JSON.stringify(obj, (key, value) => (typeof value === "bigint" ? value.toString() : value)));
|
|
256
|
+
}
|
|
257
|
+
exports.serializeBigInts = serializeBigInts;
|
|
258
|
+
/**
|
|
259
|
+
* Find the package root than contains the directory.
|
|
260
|
+
* @param moduleDir the directory of a module, typically use `__dirname`
|
|
261
|
+
* @returns the directory of the modules's package root.
|
|
262
|
+
*/
|
|
263
|
+
function findPackageRoot(moduleDir) {
|
|
264
|
+
let dir = path.resolve(moduleDir);
|
|
265
|
+
// eslint-disable-next-line no-constant-condition
|
|
266
|
+
while (true) {
|
|
267
|
+
const packageJson = path.resolve(dir, "package.json");
|
|
268
|
+
const hasPackageJson = (0, fs_1.existsSync)(packageJson) && (0, fs_1.statSync)(packageJson).isFile();
|
|
269
|
+
const nodeModules = path.resolve(dir, "node_modules");
|
|
270
|
+
const hasNodeModules = (0, fs_1.existsSync)(nodeModules) && (0, fs_1.statSync)(nodeModules).isDirectory();
|
|
271
|
+
if (hasPackageJson && hasNodeModules) {
|
|
272
|
+
return dir;
|
|
273
|
+
}
|
|
274
|
+
if (path.dirname(dir) === dir) {
|
|
275
|
+
// arrived at filesystem root without finding package root
|
|
276
|
+
throw new Error("Cannot find package root");
|
|
277
|
+
}
|
|
278
|
+
dir = path.dirname(dir);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.findPackageRoot = findPackageRoot;
|
|
282
|
+
//# sourceMappingURL=utils.js.map
|