Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Server Configuration
PORT=3001
NODE_ENV=development
NODE_ENV=development
API_SECRET=

# ETHEREUM
SIG_ETH_RPC_URL_SEPOLIA=
Expand Down
19 changes: 7 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: '22.14.0'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
Expand All @@ -36,12 +34,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: '22.14.0'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
Expand All @@ -54,6 +50,7 @@ jobs:
env:
PORT: 3001
NODE_ENV: development
API_SECRET: test-secret-key
SIG_ETH_RPC_URL_SEPOLIA: ${{ secrets.SIG_ETH_RPC_URL_SEPOLIA }}
SIG_ETH_RPC_URL_MAINNET: ${{ secrets.SIG_ETH_RPC_URL_MAINNET }}
SIG_EVM_SK_1: ${{ secrets.SIG_EVM_SK_1 }}
Expand All @@ -66,12 +63,10 @@ jobs:
SIG_SOL_SK: ${{ secrets.SIG_SOL_SK }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: '22.14.0'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.14.0
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM node:latest
FROM node:22.14.0-slim

WORKDIR /app

COPY . .
RUN corepack enable && corepack prepare pnpm@10.4.1 --activate

COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile

RUN npm install
COPY . .

CMD [ "npm", "run", "start" ]
CMD [ "pnpm", "run", "start" ]
6 changes: 0 additions & 6 deletions dist/handlers/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ async function execute({ check_signature, environment, }) {
if (check_signature) {
// TODO: add ability to call with check=true on Ethereum
throw new Error(`Ethereum can not be called with check=true due to long finalization time`);
const signature = await (0, evmTransactions_1.createSignRequestAndWaitSignature)({
chainSigContract,
publicClient,
walletClient,
});
return { signature };
}
else {
const signatureRequest = await (0, evmTransactions_1.createSignRequest)({
Expand Down
46 changes: 5 additions & 41 deletions dist/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ var __importStar = (this && this.__importStar) || (function () {
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlockchainHandlerRegistry = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const ethereum = __importStar(require("./ethereum"));
const solana = __importStar(require("./solana"));
class BlockchainHandlerRegistry {
constructor() {
this._handlers = {};
this._loadErrors = [];
}
_handlers = {};
register(chainName, handler) {
this._handlers[chainName] = handler;
return this;
Expand All @@ -58,42 +55,9 @@ class BlockchainHandlerRegistry {
getSupportedChains() {
return Object.keys(this._handlers);
}
getLoadErrors() {
return this._loadErrors;
}
loadHandlersFromDirectory(directory) {
try {
const files = fs
.readdirSync(directory)
.filter(file => file !== 'index.ts' &&
file !== 'index.js' &&
(file.endsWith('.ts') || file.endsWith('.js')));
files.forEach(file => {
const filePath = path.join(directory, file);
try {
let handler;
try {
handler = require(filePath);
}
catch (requireError) {
this._loadErrors.push({ file, error: requireError });
return;
}
if (handler) {
this.register(handler.chainName, handler);
}
}
catch (error) {
this._loadErrors.push({ file, error });
}
});
}
catch (error) {
this._loadErrors.push({ directory, error });
}
}
}
exports.BlockchainHandlerRegistry = BlockchainHandlerRegistry;
const registry = new BlockchainHandlerRegistry();
registry.loadHandlersFromDirectory(__dirname);
registry.register(ethereum.chainName, ethereum);
registry.register(solana.chainName, solana);
exports.default = registry;
34 changes: 18 additions & 16 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 1 addition & 19 deletions dist/utils/evmTransactions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSignRequest = exports.createSignRequestAndWaitSignature = exports.getCustomTransactionArgs = exports.getSignArgs = void 0;
exports.createSignRequest = exports.getCustomTransactionArgs = exports.getSignArgs = void 0;
const getSignArgs = () => {
const payload = new Uint8Array(Array(32)
.fill(0)
Expand All @@ -24,24 +24,6 @@ const getCustomTransactionArgs = async ({ publicClient, walletClient, }) => {
};
};
exports.getCustomTransactionArgs = getCustomTransactionArgs;
const createSignRequestAndWaitSignature = async ({ chainSigContract, publicClient, walletClient, }) => {
const transactionArgs = await (0, exports.getCustomTransactionArgs)({
publicClient,
walletClient,
});
const signArgs = (0, exports.getSignArgs)();
const rsvSignature = await chainSigContract.sign(signArgs[0], {
...signArgs[1],
retry: {
delay: 10000,
retryCount: 12,
},
transaction: transactionArgs,
});
console.log({ rsvSignature });
return rsvSignature;
};
exports.createSignRequestAndWaitSignature = createSignRequestAndWaitSignature;
const createSignRequest = async ({ chainSigContract, publicClient, walletClient, }) => {
const transactionArgs = await (0, exports.getCustomTransactionArgs)({
publicClient,
Expand Down
13 changes: 10 additions & 3 deletions dist/utils/initSolana.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const anchor = __importStar(require("@coral-xyz/anchor"));
const signet_js_1 = require("signet.js");
const useEnv_1 = require("./useEnv");
const initSolana = ({ contractAddress, environment, }) => {
const { solRpcUrlDevnet, solRpcUrlMainnet, solSk } = (0, useEnv_1.useEnv)();
const { solRpcUrlDevnet, solRpcUrlMainnet, solSk, solRootPublicKey } = (0, useEnv_1.useEnv)();
const config = {
dev: {
solanaRpcUrl: solRpcUrlDevnet,
Expand All @@ -54,6 +54,14 @@ const initSolana = ({ contractAddress, environment, }) => {
solanaPrivateKey: solSk,
},
}[environment];
if (!config.solanaRpcUrl) {
throw new Error(`Solana RPC URL for ${environment} environment is missing. Please set ${environment === 'mainnet'
? 'SIG_SOL_RPC_URL_MAINNET'
: 'SIG_SOL_RPC_URL_DEV'} in your environment.`);
}
if (!config.solanaPrivateKey) {
throw new Error(`Solana secret key is missing. Please set SIG_SOL_SK in your environment.`);
}
const connection = new web3_js_1.Connection(config.solanaRpcUrl, 'confirmed');
const keypairArray = JSON.parse(config.solanaPrivateKey);
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(keypairArray));
Expand All @@ -62,12 +70,11 @@ const initSolana = ({ contractAddress, environment, }) => {
commitment: 'confirmed',
});
const requesterKeypair = web3_js_1.Keypair.generate();
// You may want to pass a real rootPublicKey here if needed
const chainSigContract = new signet_js_1.contracts.solana.ChainSignatureContract({
provider,
programId: contractAddress,
config: {
rootPublicKey: '',
rootPublicKey: solRootPublicKey,
requesterAddress: requesterKeypair.publicKey.toString(),
},
});
Expand Down
14 changes: 9 additions & 5 deletions dist/utils/useEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.useEnv = void 0;
// In-memory rotation index for Ethereum key (module-private)
let evmKeyIndex = 0;
const useEnv = () => {
// Always rotate key on each call
const getNextEvmSk = () => {
evmKeyIndex = (evmKeyIndex % 5) + 1;
const evmSk = process.env[`SIG_EVM_SK_${evmKeyIndex}`];
return process.env[`SIG_EVM_SK_${evmKeyIndex}`];
};
const useEnv = () => {
return {
// Server configuration
port: process.env.PORT || '3001',
nodeEnv: process.env.NODE_ENV || 'development',
// Ethereum
// Ethereum (lazy getter — only rotates key when accessed)
get evmSk() {
return getNextEvmSk();
},
ethRpcUrlSepolia: process.env.SIG_ETH_RPC_URL_SEPOLIA || '',
ethRpcUrlMainnet: process.env.SIG_ETH_RPC_URL_MAINNET || '',
evmSk,
// Solana
solRpcUrlDevnet: process.env.SIG_SOL_RPC_URL_DEV || '',
solRpcUrlMainnet: process.env.SIG_SOL_RPC_URL_MAINNET || '',
solSk: process.env.SIG_SOL_SK || '',
solRootPublicKey: process.env.SIG_SOL_ROOT_PUBLIC_KEY || '',
};
};
exports.useEnv = useEnv;
7 changes: 0 additions & 7 deletions jest.config.js

This file was deleted.

31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "node dist/index.js",
"dev": "ts-node src/index.ts",
"build": "tsc",
"test": "jest --runInBand",
"test": "vitest run",
"format": "prettier --write ."
},
"keywords": [],
Expand All @@ -16,24 +16,23 @@
"type": "commonjs",
"packageManager": "pnpm@10.4.1+sha512.c753b6c3ad7afa13af388fa6d808035a008e30ea9993f58c6663e2bc5ff21679aa834db094987129aa4d488b86df57f7b634981b2f827cdcacc698cc0cfb88af",
"dependencies": {
"@coral-xyz/anchor": "^0.31.1",
"@coral-xyz/anchor": "^0.32.1",
"@solana/web3.js": "^1.98.4",
"dotenv": "^16.3.1",
"express": "^4.21.2",
"signet.js": "0.0.12-beta.17",
"viem": "^2.37.8"
"dotenv": "^17.3.1",
"express": "^5.2.1",
"signet.js": "0.4.0",
"viem": "^2.47.6"
},
"devDependencies": {
"@types/express": "^5.0.2",
"@types/jest": "^29.5.14",
"@types/node": "^22.15.23",
"@types/supertest": "^6.0.3",
"jest": "^29.7.0",
"nodemon": "^3.1.9",
"prettier": "^3.5.3",
"supertest": "^7.1.1",
"ts-jest": "^29.3.4",
"@types/express": "^5.0.6",
"@types/node": "^25.5.0",
"@types/supertest": "^7.2.0",
"nodemon": "^3.1.14",
"prettier": "^3.8.1",
"supertest": "^7.2.2",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
"tsx": "^4.21.0",
"typescript": "^6.0.2",
"vitest": "^4.1.2"
}
}
Loading
Loading