Implementation of EIP-7754
npm install @uniswap/tamperproof-transactionsImplementation of EIP-7754
``bash`
yarn add @uniswap/tamperproof-transactionsor
npm install @uniswap/tamperproof-transactions
Algorithms are specified using standard JWS-style names. The library currently supports:
`ts`
'ES256' | 'ES384' | 'ES512' | 'EdDSA' | 'PS256' | 'PS384' | 'PS512' | 'RS256' | 'RS384' | 'RS512'
---
Signs input using Web Crypto with the given algorithm.
- data: string | object. If an object is provided, it is serialized to bytes using canonical JSON (sorted keys, undefined dropped).0x
- privateKeyHex: PKCS#8-encoded private key as a hex string (with or without ).Promise
- algorithm: one of the supported algorithm names listed above.
- Returns a resolving to a hex string signature prefixed with 0x. For ECDSA algorithms, the signature is raw r || s bytes.
#### Example
`ts
import { sign } from '@uniswap/tamperproof-transactions';
const data = { method: 'eth_sendTransaction', params: { to: '0xabc...', value: '0x1' } };
const privateKeyHex = '0x...'; // PKCS#8 private key, hex-encoded
const signature = await sign(data, privateKeyHex, 'RS256');
`
---
Verifies a signature by fetching a manifest of public keys (over HTTPS) and selecting the key with matching id.
- calldata: string | object (object is canonicalized the same way as in sign).0x
- signatureHex: hex string signature (with or without ).URL
- url: a instance pointing to the manifest (must be https:).
- id: string identifier of the public key within the manifest.
#### Example
`ts
import { verifyAsyncJson } from '@uniswap/tamperproof-transactions';
const url = new URL('https://example.com/keys.json');
const ok = await verifyAsyncJson({ foo: 'bar' }, '0x...', url, '1');
`
---
Resolves a DNS TXT record for host using DNS-over-HTTPS, extracts a TWIST= path, fetches the manifest over HTTPS, and verifies the signature using the key with the provided id.
- calldata: string.0x
- signatureHex: hex string signature (with or without ).TWIST=
- host: domain name to query for a TXT record containing .
- id: string identifier of the public key within the manifest.
#### Example
`ts
import { verifyAsyncDns } from '@uniswap/tamperproof-transactions';
const ok = await verifyAsyncDns('hello', '0x...', 'example.com', '1');
`
---
Lower-level verification helper if you already have a CryptoKey public key object.
- publicKey: a Web Crypto CryptoKey imported for verification.
- algorithm: one of the supported algorithm names listed above.
---
Generates a JSON manifest string containing an array of public keys.
#### Types
`ts`
type PublicKey = {
key: string; // SPKI-encoded public key as hex (with or without 0x)
algorithm: 'ES256' | 'ES384' | 'ES512' | 'EdDSA' | 'PS256' | 'PS384' | 'PS512' | 'RS256' | 'RS384' | 'RS512';
};
The returned JSON has the shape:
`json`
{
"publicKeys": [
{ "id": "1", "alg": "RS256", "publicKey": "0x..." }
]
}
#### Example
`ts
import { generate } from '@uniswap/tamperproof-transactions';
const json = generate({ key: '0x...', algorithm: 'RS256' });
`
---
The following helpers are also exported:
- canonicalStringify(value: unknown): stringserializeRequestPayload
-
These are used internally to canonicalize objects before signing/verifying.
---
MIT