-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update build process and add new configuration files; improve pa…
…ckage exports and documentation
- Loading branch information
Showing
12 changed files
with
218 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,4 @@ | |
/coverage.data | ||
/coverage/ | ||
|
||
# Build files | ||
/dist | ||
|
||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
bun run format | ||
bun run test | ||
npm run format | ||
npm run test | ||
npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultContractAddress = exports.defaultABI = exports.whenActive = exports.isActive = exports.decryptMessage = exports.encryptMessage = exports.getTimestamp = exports.default = void 0; | ||
const ABI_1 = require("./src/ABI"); | ||
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return ABI_1.methods; } }); | ||
Object.defineProperty(exports, "defaultContractAddress", { enumerable: true, get: function () { return ABI_1.defaultContractAddress; } }); | ||
Object.defineProperty(exports, "defaultABI", { enumerable: true, get: function () { return ABI_1.defaultABI; } }); | ||
const { getTimestamp, encryptMessage, decryptMessage, isActive, whenActive } = ABI_1.methods; | ||
exports.getTimestamp = getTimestamp; | ||
exports.encryptMessage = encryptMessage; | ||
exports.decryptMessage = decryptMessage; | ||
exports.isActive = isActive; | ||
exports.whenActive = whenActive; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use strict"; | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.v1_0 = void 0; | ||
exports.v1_0 = [ | ||
{ inputs: [], stateMutability: "nonpayable", type: "constructor" }, | ||
{ | ||
inputs: [{ internalType: "bytes", name: "encryptedMsg", type: "bytes" }], | ||
name: "decryptMessage", | ||
outputs: [{ internalType: "string", name: "", type: "string" }], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [ | ||
{ internalType: "string", name: "message", type: "string" }, | ||
{ internalType: "uint256", name: "timestamp", type: "uint256" }, | ||
], | ||
name: "encryptMessage", | ||
outputs: [{ internalType: "bytes", name: "", type: "bytes" }], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [], | ||
name: "getTimestamp", | ||
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [{ internalType: "bytes", name: "encryptedMsg", type: "bytes" }], | ||
name: "isActive", | ||
outputs: [{ internalType: "bool", name: "", type: "bool" }], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [{ internalType: "bytes", name: "encryptedMsg", type: "bytes" }], | ||
name: "whenActive", | ||
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.methods = exports.defaultContractAddress = exports.defaultABI = void 0; | ||
const ethers_1 = require("ethers"); | ||
const abi_1 = require("./abi"); | ||
const config_1 = __importDefault(require("../config")); | ||
const abi = [abi_1.v1_0]; | ||
exports.defaultABI = abi[0]; | ||
exports.defaultContractAddress = config_1.default.CONTRACT_ADDRESS; | ||
const defaults = { | ||
provider: new ethers_1.ethers.JsonRpcProvider(config_1.default.RPC_URL), | ||
contractAddress: config_1.default.CONTRACT_ADDRESS, | ||
rpcUrl: config_1.default.RPC_URL, | ||
abi: abi[0], | ||
}; | ||
const getDefaults = (_config) => ({ | ||
provider: _config.provider || new ethers_1.ethers.JsonRpcProvider(_config.rpcUrl || config_1.default.RPC_URL), | ||
contractAddress: _config.contractAddress || config_1.default.CONTRACT_ADDRESS, | ||
rpcUrl: _config.rpcUrl || config_1.default.RPC_URL, | ||
abi: _config.abi || abi[0], | ||
}); | ||
exports.methods = { | ||
getTimestamp: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (_config = defaults) { | ||
const { provider, contractAddress, abi } = getDefaults(_config); | ||
const contract = new ethers_1.ethers.Contract(contractAddress, abi, provider); | ||
const timestamp = yield contract.getTimestamp(); | ||
return Number(timestamp); | ||
}), | ||
encryptMessage: (message_1, timestamp_1, ...args_1) => __awaiter(void 0, [message_1, timestamp_1, ...args_1], void 0, function* (message, timestamp, _config = defaults) { | ||
const { provider, contractAddress, abi } = getDefaults(_config); | ||
const contract = new ethers_1.ethers.Contract(contractAddress, abi, provider); | ||
return yield contract.encryptMessage(message, timestamp); | ||
}), | ||
decryptMessage: (encryptedMessage_1, ...args_1) => __awaiter(void 0, [encryptedMessage_1, ...args_1], void 0, function* (encryptedMessage, _config = defaults) { | ||
var _a, _b; | ||
try { | ||
const { provider, contractAddress, abi } = getDefaults(_config); | ||
const contract = new ethers_1.ethers.Contract(contractAddress, abi, provider); | ||
return yield contract.decryptMessage(encryptedMessage); | ||
} | ||
catch (error) { | ||
if (((_b = (_a = error === null || error === void 0 ? void 0 : error.revert) === null || _a === void 0 ? void 0 : _a.args) === null || _b === void 0 ? void 0 : _b.length) > 0) | ||
throw new Error(error.revert.args[0]); | ||
throw new Error(error.message); | ||
} | ||
}), | ||
isActive: (encryptedMsg_1, ...args_1) => __awaiter(void 0, [encryptedMsg_1, ...args_1], void 0, function* (encryptedMsg, _config = defaults) { | ||
const { provider, contractAddress, abi } = getDefaults(_config); | ||
const contract = new ethers_1.ethers.Contract(contractAddress, abi, provider); | ||
return yield contract.isActive(encryptedMsg); | ||
}), | ||
whenActive: (encryptedMsg_1, ...args_1) => __awaiter(void 0, [encryptedMsg_1, ...args_1], void 0, function* (encryptedMsg, _config = defaults) { | ||
const { provider, contractAddress, abi } = getDefaults(_config); | ||
const contract = new ethers_1.ethers.Contract(contractAddress, abi, provider); | ||
const timestamp = yield contract.whenActive(encryptedMsg); | ||
return Number(timestamp); | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const config = { | ||
RPC_URL: "https://sepolia.base.org", | ||
CHAIN_ID: 84532, | ||
CONTRACT_ADDRESS: "0x9237084a3bd3c113f26f589d703321080d9532f9", | ||
}; | ||
exports.default = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const index_1 = __importDefault(require("../index")); | ||
test("getTimestamp", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const timestamp = yield index_1.default.getTimestamp(); | ||
expect(typeof timestamp).toBe("number"); | ||
})); | ||
test("encryptMessage", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const timestamp = yield index_1.default.getTimestamp(); | ||
const encryptedMessage = yield index_1.default.encryptMessage("test", timestamp); | ||
expect(typeof encryptedMessage).toBe("string"); | ||
})); | ||
test("decryptMessage", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const timestamp = yield index_1.default.getTimestamp(); | ||
const encryptedMessage = yield index_1.default.encryptMessage("test", timestamp); | ||
const decryptedMessage = yield index_1.default.decryptMessage(encryptedMessage); | ||
expect(decryptedMessage).toBe("test"); | ||
})); | ||
test("isActive", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const timestamp = yield index_1.default.getTimestamp(); | ||
const encryptedMessage = yield index_1.default.encryptMessage("test", timestamp); | ||
const active = yield index_1.default.isActive(encryptedMessage); | ||
expect(active).toBe(true); | ||
})); | ||
test("whenActive", () => __awaiter(void 0, void 0, void 0, function* () { | ||
const timestamp = yield index_1.default.getTimestamp(); | ||
const encryptedMessage = yield index_1.default.encryptMessage("test", timestamp); | ||
const whenActive = yield index_1.default.whenActive(encryptedMessage); | ||
expect(whenActive).toBe(timestamp); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters