Implementation of EIP-7754
yarn add @uniswap/tamperproof-transactions
# or
npm install @uniswap/tamperproof-transactions
export enum SigningAlgorithm {
RSA = "RSA-SHA256",
RSA_PSS = "RSA-PSS",
ECDSA = "SHA256"
}
Signs a string using the provided private key and algorithm.
import { sign, SigningAlgorithm } from '@uniswap/tamperproof-transactions';
import { generateKeyPairSync } from 'crypto';
const { privateKey } = generateKeyPairSync('rsa', { modulusLength: 2048 });
const data = 'hello world';
const signature = sign(data, privateKey, SigningAlgorithm.RSA);
verifySync(calldata: string, signature: string, algorithm: SigningAlgorithm, publicKey: KeyObject): boolean
Verifies a signature synchronously.
import { sign, verifySync, SigningAlgorithm } from '@uniswap/tamperproof-transactions';
import { generateKeyPairSync } from 'crypto';
const { privateKey, publicKey } = generateKeyPairSync('rsa', { modulusLength: 2048 });
const data = 'hello world';
const signature = sign(data, privateKey, SigningAlgorithm.RSA);
const isValid = verifySync(data, signature, SigningAlgorithm.RSA, publicKey);
Verifies a signature by fetching a public key from a DNS TXT record.
import { verifyAsyncDns } from '@uniswap/tamperproof-transactions';
const isValid = await verifyAsyncDns('data', 'signature', 'example.com');
Verifies a signature by fetching a public key from a JSON endpoint.
import { verifyAsyncJson } from '@uniswap/tamperproof-transactions';
const isValid = await verifyAsyncJson('data', 'signature', 'https://example.com/keys.json');
Generates a JSON string containing an array of public keys.
type PublicKey = {
key: string;
algorithm: SigningAlgorithm;
};
import { generate, SigningAlgorithm } from '@uniswap/tamperproof-transactions';
const publicKey = {
key: 'hex-encoded-key',
algorithm: SigningAlgorithm.RSA
};
const json = generate(publicKey);
MIT