@claritydao/midnight-agora-sdk 0.1.0
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/.prettierrc +1 -0
- package/LICENSE +0 -0
- package/README.md +1134 -0
- package/dist/browser-providers.d.ts +21 -0
- package/dist/browser-providers.d.ts.map +1 -0
- package/dist/browser-providers.js +147 -0
- package/dist/browser-providers.js.map +1 -0
- package/dist/common-types.d.ts +29 -0
- package/dist/common-types.d.ts.map +1 -0
- package/dist/common-types.js +2 -0
- package/dist/common-types.js.map +1 -0
- package/dist/errors.d.ts +67 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +108 -0
- package/dist/errors.js.map +1 -0
- package/dist/governor-api.d.ts +348 -0
- package/dist/governor-api.d.ts.map +1 -0
- package/dist/governor-api.js +716 -0
- package/dist/governor-api.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/manager.d.ts +87 -0
- package/dist/manager.d.ts.map +1 -0
- package/dist/manager.js +93 -0
- package/dist/manager.js.map +1 -0
- package/dist/types.d.ts +307 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +77 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/index.d.ts +34 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +57 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/validators.d.ts +52 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +160 -0
- package/dist/validators.js.map +1 -0
- package/eslint.config.mjs +48 -0
- package/package.json +39 -0
- package/src/browser-providers.ts +274 -0
- package/src/common-types.ts +51 -0
- package/src/errors.ts +124 -0
- package/src/governor-api.ts +948 -0
- package/src/index.ts +51 -0
- package/src/manager.ts +203 -0
- package/src/types.ts +403 -0
- package/src/utils/index.ts +60 -0
- package/src/validators.ts +245 -0
- package/test/README.md +409 -0
- package/test/errors.test.ts +179 -0
- package/test/integration/governor-api.test.ts +370 -0
- package/test/mocks/providers.ts +130 -0
- package/test/types.test.ts +112 -0
- package/test/utils.test.ts +111 -0
- package/test/validators.test.ts +368 -0
- package/test/wasm-init.test.ts +132 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides utility functions.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Generates a buffer containing a series of randomly generated bytes.
|
|
8
|
+
*
|
|
9
|
+
* @param length The number of bytes to generate.
|
|
10
|
+
* @returns A `Uint8Array` representing `length` randomly generated bytes.
|
|
11
|
+
*/
|
|
12
|
+
export declare const randomBytes: (length: number) => Uint8Array;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a wallet address string to a Uint8Array (32 bytes).
|
|
15
|
+
*
|
|
16
|
+
* @param address The wallet address string.
|
|
17
|
+
* @returns A 32-byte Uint8Array representation of the address.
|
|
18
|
+
*/
|
|
19
|
+
export declare const addressToBytes: (address: string) => Uint8Array;
|
|
20
|
+
/**
|
|
21
|
+
* Converts a Uint8Array to a hex string.
|
|
22
|
+
*
|
|
23
|
+
* @param bytes The bytes to convert.
|
|
24
|
+
* @returns Hex string representation.
|
|
25
|
+
*/
|
|
26
|
+
export declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Converts a hex string to a Uint8Array.
|
|
29
|
+
*
|
|
30
|
+
* @param hex The hex string to convert.
|
|
31
|
+
* @returns Uint8Array representation.
|
|
32
|
+
*/
|
|
33
|
+
export declare const hexToBytes: (hex: string) => Uint8Array;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,KAAG,UAI5C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,UAQhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,UAAU,KAAG,MAI9C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,UAOxC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides utility functions.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Generates a buffer containing a series of randomly generated bytes.
|
|
8
|
+
*
|
|
9
|
+
* @param length The number of bytes to generate.
|
|
10
|
+
* @returns A `Uint8Array` representing `length` randomly generated bytes.
|
|
11
|
+
*/
|
|
12
|
+
export const randomBytes = (length) => {
|
|
13
|
+
const bytes = new Uint8Array(length);
|
|
14
|
+
crypto.getRandomValues(bytes);
|
|
15
|
+
return bytes;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Converts a wallet address string to a Uint8Array (32 bytes).
|
|
19
|
+
*
|
|
20
|
+
* @param address The wallet address string.
|
|
21
|
+
* @returns A 32-byte Uint8Array representation of the address.
|
|
22
|
+
*/
|
|
23
|
+
export const addressToBytes = (address) => {
|
|
24
|
+
const addressBytes = new Uint8Array(32);
|
|
25
|
+
const addressStr = address.replace(/[^0-9a-f]/gi, "");
|
|
26
|
+
const addressHex = addressStr.slice(-64);
|
|
27
|
+
for (let i = 0; i < Math.min(32, addressHex.length / 2); i++) {
|
|
28
|
+
addressBytes[i] = parseInt(addressHex.substr(i * 2, 2), 16);
|
|
29
|
+
}
|
|
30
|
+
return addressBytes;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Converts a Uint8Array to a hex string.
|
|
34
|
+
*
|
|
35
|
+
* @param bytes The bytes to convert.
|
|
36
|
+
* @returns Hex string representation.
|
|
37
|
+
*/
|
|
38
|
+
export const bytesToHex = (bytes) => {
|
|
39
|
+
return Array.from(bytes)
|
|
40
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
41
|
+
.join("");
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Converts a hex string to a Uint8Array.
|
|
45
|
+
*
|
|
46
|
+
* @param hex The hex string to convert.
|
|
47
|
+
* @returns Uint8Array representation.
|
|
48
|
+
*/
|
|
49
|
+
export const hexToBytes = (hex) => {
|
|
50
|
+
const cleanHex = hex.replace(/^0x/, "");
|
|
51
|
+
const bytes = new Uint8Array(cleanHex.length / 2);
|
|
52
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
53
|
+
bytes[i] = parseInt(cleanHex.substr(i * 2, 2), 16);
|
|
54
|
+
}
|
|
55
|
+
return bytes;
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAc,EAAE;IACxD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAe,EAAc,EAAE;IAC5D,MAAM,YAAY,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACxC,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IACtD,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;I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|
|
2
|
+
* Validation utilities for the Agora DAO Governor SDK.
|
|
3
|
+
*
|
|
4
|
+
* @module validators
|
|
5
|
+
*/
|
|
6
|
+
import type { GovernanceConfig, GovernorConfig, DeploymentConfig, TokenConfig } from "./types";
|
|
7
|
+
import { VoteChoice } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Validates that a value is a non-empty string.
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateNonEmptyString(value: string, parameterName: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Validates that a string does not exceed a maximum length.
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateMaxLength(value: string, maxLength: number, parameterName: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Validates that a value is a valid Uint8Array address (32 bytes).
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateAddress(address: Uint8Array, parameterName: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Validates that a bigint is positive.
|
|
22
|
+
*/
|
|
23
|
+
export declare function validatePositiveBigInt(value: bigint, parameterName: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Validates that a bigint is non-negative.
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateNonNegativeBigInt(value: bigint, parameterName: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Validates a vote choice value.
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateVoteChoice(choice: VoteChoice): void;
|
|
32
|
+
/**
|
|
33
|
+
* Validates proposal parameters.
|
|
34
|
+
*/
|
|
35
|
+
export declare function validateProposal(title: string, description: string, creator: Uint8Array): void;
|
|
36
|
+
/**
|
|
37
|
+
* Validates governance configuration.
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateGovernanceConfig(config: GovernanceConfig): void;
|
|
40
|
+
/**
|
|
41
|
+
* Validates governor configuration.
|
|
42
|
+
*/
|
|
43
|
+
export declare function validateGovernorConfig(config: GovernorConfig): void;
|
|
44
|
+
/**
|
|
45
|
+
* Validates token configuration.
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateTokenConfig(config: TokenConfig): void;
|
|
48
|
+
/**
|
|
49
|
+
* Validates complete deployment configuration.
|
|
50
|
+
*/
|
|
51
|
+
export declare function validateDeploymentConfig(config: DeploymentConfig): void;
|
|
52
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAUrC;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,GACpB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,UAAU,EACnB,aAAa,EAAE,MAAM,GACpB,IAAI,CAUN;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,GACpB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,GACpB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAS3D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,UAAU,GAClB,IAAI,CAQN;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAsBvE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAwCnE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAc7D;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAiBvE"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for the Agora DAO Governor SDK.
|
|
3
|
+
*
|
|
4
|
+
* @module validators
|
|
5
|
+
*/
|
|
6
|
+
import { InvalidParameterError, InvalidConfigurationError } from "./errors";
|
|
7
|
+
import { VoteChoice } from "./types";
|
|
8
|
+
// Constants for validation limits
|
|
9
|
+
const MAX_TITLE_LENGTH = 256;
|
|
10
|
+
const MAX_DESCRIPTION_LENGTH = 10000;
|
|
11
|
+
const MAX_TOKEN_NAME_LENGTH = 64;
|
|
12
|
+
const MAX_TOKEN_SYMBOL_LENGTH = 16;
|
|
13
|
+
const MAX_TOKEN_DECIMALS = 18n;
|
|
14
|
+
const MIN_VOTING_PERIOD = 60n;
|
|
15
|
+
/**
|
|
16
|
+
* Validates that a value is a non-empty string.
|
|
17
|
+
*/
|
|
18
|
+
export function validateNonEmptyString(value, parameterName) {
|
|
19
|
+
if (typeof value !== "string") {
|
|
20
|
+
throw new InvalidParameterError(parameterName, "must be a string");
|
|
21
|
+
}
|
|
22
|
+
if (value.trim().length === 0) {
|
|
23
|
+
throw new InvalidParameterError(parameterName, "cannot be empty");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates that a string does not exceed a maximum length.
|
|
28
|
+
*/
|
|
29
|
+
export function validateMaxLength(value, maxLength, parameterName) {
|
|
30
|
+
if (value.length > maxLength) {
|
|
31
|
+
throw new InvalidParameterError(parameterName, `cannot exceed ${maxLength} characters (got ${value.length})`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validates that a value is a valid Uint8Array address (32 bytes).
|
|
36
|
+
*/
|
|
37
|
+
export function validateAddress(address, parameterName) {
|
|
38
|
+
if (!(address instanceof Uint8Array)) {
|
|
39
|
+
throw new InvalidParameterError(parameterName, "must be a Uint8Array");
|
|
40
|
+
}
|
|
41
|
+
if (address.length !== 32) {
|
|
42
|
+
throw new InvalidParameterError(parameterName, `must be exactly 32 bytes (got ${address.length})`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Validates that a bigint is positive.
|
|
47
|
+
*/
|
|
48
|
+
export function validatePositiveBigInt(value, parameterName) {
|
|
49
|
+
if (typeof value !== "bigint") {
|
|
50
|
+
throw new InvalidParameterError(parameterName, "must be a bigint");
|
|
51
|
+
}
|
|
52
|
+
if (value <= 0n) {
|
|
53
|
+
throw new InvalidParameterError(parameterName, "must be greater than 0");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validates that a bigint is non-negative.
|
|
58
|
+
*/
|
|
59
|
+
export function validateNonNegativeBigInt(value, parameterName) {
|
|
60
|
+
if (typeof value !== "bigint") {
|
|
61
|
+
throw new InvalidParameterError(parameterName, "must be a bigint");
|
|
62
|
+
}
|
|
63
|
+
if (value < 0n) {
|
|
64
|
+
throw new InvalidParameterError(parameterName, "cannot be negative");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Validates a vote choice value.
|
|
69
|
+
*/
|
|
70
|
+
export function validateVoteChoice(choice) {
|
|
71
|
+
if (![VoteChoice.For, VoteChoice.Against, VoteChoice.Abstain].includes(choice)) {
|
|
72
|
+
throw new InvalidParameterError("choice", "must be VoteChoice.For, VoteChoice.Against, or VoteChoice.Abstain");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Validates proposal parameters.
|
|
77
|
+
*/
|
|
78
|
+
export function validateProposal(title, description, creator) {
|
|
79
|
+
validateNonEmptyString(title, "title");
|
|
80
|
+
validateMaxLength(title, MAX_TITLE_LENGTH, "title");
|
|
81
|
+
validateNonEmptyString(description, "description");
|
|
82
|
+
validateMaxLength(description, MAX_DESCRIPTION_LENGTH, "description");
|
|
83
|
+
validateAddress(creator, "creator");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Validates governance configuration.
|
|
87
|
+
*/
|
|
88
|
+
export function validateGovernanceConfig(config) {
|
|
89
|
+
validatePositiveBigInt(config.votingPeriod, "votingPeriod");
|
|
90
|
+
validatePositiveBigInt(config.quorumThreshold, "quorumThreshold");
|
|
91
|
+
validatePositiveBigInt(config.proposalThreshold, "proposalThreshold");
|
|
92
|
+
validatePositiveBigInt(config.proposalLifetime, "proposalLifetime");
|
|
93
|
+
validateNonNegativeBigInt(config.executionDelay, "executionDelay");
|
|
94
|
+
validateNonNegativeBigInt(config.gracePeriod, "gracePeriod");
|
|
95
|
+
validatePositiveBigInt(config.minStakeAmount, "minStakeAmount");
|
|
96
|
+
validateNonNegativeBigInt(config.stakingPeriod, "stakingPeriod");
|
|
97
|
+
// Logical validations
|
|
98
|
+
if (config.votingPeriod < MIN_VOTING_PERIOD) {
|
|
99
|
+
throw new InvalidConfigurationError(`votingPeriod must be at least ${MIN_VOTING_PERIOD} seconds`);
|
|
100
|
+
}
|
|
101
|
+
if (config.proposalThreshold > config.quorumThreshold) {
|
|
102
|
+
throw new InvalidConfigurationError("proposalThreshold cannot exceed quorumThreshold");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Validates governor configuration.
|
|
107
|
+
*/
|
|
108
|
+
export function validateGovernorConfig(config) {
|
|
109
|
+
validateGovernanceConfig(config.governance);
|
|
110
|
+
validateNonNegativeBigInt(config.executionDelay, "executionDelay");
|
|
111
|
+
validateNonNegativeBigInt(config.gracePeriod, "gracePeriod");
|
|
112
|
+
validatePositiveBigInt(config.maxActiveProposals, "maxActiveProposals");
|
|
113
|
+
validatePositiveBigInt(config.proposalLifetime, "proposalLifetime");
|
|
114
|
+
if (typeof config.emergencyVetoEnabled !== "boolean") {
|
|
115
|
+
throw new InvalidParameterError("emergencyVetoEnabled", "must be a boolean");
|
|
116
|
+
}
|
|
117
|
+
if (config.emergencyVetoEnabled) {
|
|
118
|
+
validatePositiveBigInt(config.emergencyVetoThreshold, "emergencyVetoThreshold");
|
|
119
|
+
}
|
|
120
|
+
// Check consistency
|
|
121
|
+
if (config.executionDelay !== config.governance.executionDelay) {
|
|
122
|
+
throw new InvalidConfigurationError("executionDelay must match governance.executionDelay");
|
|
123
|
+
}
|
|
124
|
+
if (config.gracePeriod !== config.governance.gracePeriod) {
|
|
125
|
+
throw new InvalidConfigurationError("gracePeriod must match governance.gracePeriod");
|
|
126
|
+
}
|
|
127
|
+
if (config.proposalLifetime !== config.governance.proposalLifetime) {
|
|
128
|
+
throw new InvalidConfigurationError("proposalLifetime must match governance.proposalLifetime");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Validates token configuration.
|
|
133
|
+
*/
|
|
134
|
+
export function validateTokenConfig(config) {
|
|
135
|
+
validateNonEmptyString(config.name, "token.name");
|
|
136
|
+
validateMaxLength(config.name, MAX_TOKEN_NAME_LENGTH, "token.name");
|
|
137
|
+
validateNonEmptyString(config.symbol, "token.symbol");
|
|
138
|
+
validateMaxLength(config.symbol, MAX_TOKEN_SYMBOL_LENGTH, "token.symbol");
|
|
139
|
+
validatePositiveBigInt(config.decimals, "token.decimals");
|
|
140
|
+
if (config.decimals > MAX_TOKEN_DECIMALS) {
|
|
141
|
+
throw new InvalidConfigurationError(`token.decimals cannot exceed ${MAX_TOKEN_DECIMALS}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Validates complete deployment configuration.
|
|
146
|
+
*/
|
|
147
|
+
export function validateDeploymentConfig(config) {
|
|
148
|
+
validateGovernorConfig(config.governor);
|
|
149
|
+
validateTokenConfig(config.token);
|
|
150
|
+
validateAddress(config.adminKey, "adminKey");
|
|
151
|
+
// Security check: warn about predictable admin keys
|
|
152
|
+
const allZeros = config.adminKey.every((byte) => byte === 0);
|
|
153
|
+
const allOnes = config.adminKey.every((byte) => byte === 1);
|
|
154
|
+
const sequential = config.adminKey[0] === 1 &&
|
|
155
|
+
config.adminKey.slice(1).every((byte) => byte === 0);
|
|
156
|
+
if (allZeros || allOnes || sequential) {
|
|
157
|
+
console.warn("WARNING: adminKey appears to be predictable. Use cryptographically secure random bytes in production.");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAO5E,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,kCAAkC;AAClC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAa,EACb,aAAqB;IAErB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,qBAAqB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,qBAAqB,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AA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QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;QACxB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;IAEvD,IAAI,QAAQ,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;QACtC,OAAO,CAAC,IAAI,CACV,uGAAuG,CACxG,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import js from "@eslint/js";
|
|
2
|
+
import plugin from "@typescript-eslint/eslint-plugin";
|
|
3
|
+
import parser from "@typescript-eslint/parser";
|
|
4
|
+
import pluginPrettier from "eslint-plugin-prettier";
|
|
5
|
+
|
|
6
|
+
export default [
|
|
7
|
+
js.configs.recommended,
|
|
8
|
+
{
|
|
9
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
10
|
+
languageOptions: {
|
|
11
|
+
parser,
|
|
12
|
+
parserOptions: {
|
|
13
|
+
ecmaVersion: "latest",
|
|
14
|
+
sourceType: "module",
|
|
15
|
+
project: ["./tsconfig.json"]
|
|
16
|
+
},
|
|
17
|
+
globals: {
|
|
18
|
+
// Browser globals
|
|
19
|
+
window: "readonly",
|
|
20
|
+
fetch: "readonly",
|
|
21
|
+
crypto: "readonly",
|
|
22
|
+
console: "readonly",
|
|
23
|
+
Window: "readonly",
|
|
24
|
+
// Node globals (for type definitions)
|
|
25
|
+
Buffer: "readonly"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
plugins: {
|
|
29
|
+
"@typescript-eslint": plugin,
|
|
30
|
+
prettier: pluginPrettier
|
|
31
|
+
},
|
|
32
|
+
rules: {
|
|
33
|
+
"prettier/prettier": "error",
|
|
34
|
+
"@typescript-eslint/no-misused-promises": "off",
|
|
35
|
+
"@typescript-eslint/no-floating-promises": "warn",
|
|
36
|
+
"@typescript-eslint/promise-function-async": "off",
|
|
37
|
+
"@typescript-eslint/no-redeclare": "off",
|
|
38
|
+
"@typescript-eslint/no-invalid-void-type": "off",
|
|
39
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
40
|
+
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
41
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
42
|
+
"@typescript-eslint/consistent-type-definitions": "off",
|
|
43
|
+
// Use TypeScript-aware no-unused-vars rule
|
|
44
|
+
"no-unused-vars": "off",
|
|
45
|
+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@claritydao/midnight-agora-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@midnight-ntwrk/compact-runtime": "0.11.0-rc.1",
|
|
9
|
+
"@midnight-ntwrk/dapp-connector-api": "4.0.0-beta.2",
|
|
10
|
+
"@midnight-ntwrk/ledger-v6": "6.2.0-rc.3",
|
|
11
|
+
"@midnight-ntwrk/midnight-js-contracts": "3.0.0-alpha.11",
|
|
12
|
+
"@midnight-ntwrk/midnight-js-fetch-zk-config-provider": "3.0.0-alpha.11",
|
|
13
|
+
"@midnight-ntwrk/midnight-js-http-client-proof-provider": "3.0.0-alpha.11",
|
|
14
|
+
"@midnight-ntwrk/midnight-js-indexer-public-data-provider": "3.0.0-alpha.11",
|
|
15
|
+
"@midnight-ntwrk/midnight-js-level-private-state-provider": "3.0.0-alpha.11",
|
|
16
|
+
"@midnight-ntwrk/midnight-js-network-id": "3.0.0-alpha.11",
|
|
17
|
+
"@midnight-ntwrk/midnight-js-types": "3.0.0-alpha.11",
|
|
18
|
+
"@midnight-ntwrk/midnight-js-utils": "3.0.0-alpha.11",
|
|
19
|
+
"@midnight-ntwrk/wallet-sdk-address-format": "3.0.0-beta.11",
|
|
20
|
+
"@midnight-ntwrk/zswap": "4.0.0",
|
|
21
|
+
"fp-ts": "^2.16.11",
|
|
22
|
+
"rxjs": "^7.8.2",
|
|
23
|
+
"semver": "^7.7.3",
|
|
24
|
+
"@agora-dao-midnight/contract": "0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.10.2",
|
|
28
|
+
"@types/semver": "^7.7.1",
|
|
29
|
+
"pino": "^9.14.0",
|
|
30
|
+
"typescript": "^5.7.2",
|
|
31
|
+
"vitest": "^3.2.4"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"dev": "tsc --watch",
|
|
36
|
+
"test": "vitest",
|
|
37
|
+
"lint": "eslint src"
|
|
38
|
+
}
|
|
39
|
+
}
|