Skip to content

Uniswap/tamperproof-transactions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tamperproof-transactions

Implementation of EIP-7754

Installation

yarn add @uniswap/tamperproof-transactions
# or
npm install @uniswap/tamperproof-transactions

API

SigningAlgorithm

export enum SigningAlgorithm {
  RSA = "RSA-SHA256",
  RSA_PSS = "RSA-PSS",
  ECDSA = "SHA256"
}

sign(data: string, privateKey: KeyObject, algorithm: SigningAlgorithm): string

Signs a string using the provided private key and algorithm.

Example

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.

Example

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);

verifyAsyncDns(calldata: string, signature: string, host: string, id?: number): Promise<boolean>

Verifies a signature by fetching a public key from a DNS TXT record.

Example

import { verifyAsyncDns } from '@uniswap/tamperproof-transactions';

const isValid = await verifyAsyncDns('data', 'signature', 'example.com');

verifyAsyncJson(calldata: string, signature: string, url: string, id?: number): Promise<boolean>

Verifies a signature by fetching a public key from a JSON endpoint.

Example

import { verifyAsyncJson } from '@uniswap/tamperproof-transactions';

const isValid = await verifyAsyncJson('data', 'signature', 'https://example.com/keys.json');

generate(...publicKeys: PublicKey[]): string

Generates a JSON string containing an array of public keys.

Types

type PublicKey = {
  key: string;
  algorithm: SigningAlgorithm;
};

Example

import { generate, SigningAlgorithm } from '@uniswap/tamperproof-transactions';

const publicKey = {
  key: 'hex-encoded-key',
  algorithm: SigningAlgorithm.RSA
};

const json = generate(publicKey);

License

MIT

About

Implementation of EIP-7754

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •