{"_id":"@anders94/siwe","name":"@anders94/siwe","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@anders94/siwe","version":"1.0.0","type":"module","main":"index.js","scripts":{"test":"vitest","build":"tsc","prepublishOnly":"npm run build"},"keywords":[],"author":{"name":"Anders Brownworth"},"license":"MIT","description":"A lightweight Sign In With Ethereum TypeScript module.","publishConfig":{"access":"public"},"dependencies":{"@noble/hashes":"^1.8.0","@noble/secp256k1":"^3.0.0"},"devDependencies":{"@types/node":"^25.0.3","typescript":"^5.9.3","vitest":"^4.0.16"},"_id":"@anders94/siwe@1.0.0","gitHead":"a08bf1c9f121528069fd12fffc69fc4db6c9f015","_nodeVersion":"20.18.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-NqHIzwFRd7bD4qNxaX+rXuNjEXMCTSNfxJy3DgzbsCYq5YfaulJpBQ1hRh/EhgZRdVBg5HyqSl5zOIqOTFublA==","shasum":"2a9dd8604926255ec3c0851d80e302a6c9719831","tarball":"https://registry.npmjs.org/@anders94/siwe/-/siwe-1.0.0.tgz","fileCount":7,"unpackedSize":18032,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICHkjSyMcWMIdgWKQmA1v8KnUkiKL9BHjjQNRr2Zv5ZoAiBLJmm+dU6BN4ZxCxMH+2T9dqmgIy165hmPzn2Z4WTLiA=="}]},"_npmUser":{"name":"anders94","email":"anders-npmjs@evantide.com"},"directories":{},"maintainers":[{"name":"anders94","email":"anders-npmjs@evantide.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/siwe_1.0.0_1767658544694_0.26323148212158154"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-06T00:15:44.493Z","1.0.0":"2026-01-06T00:15:44.845Z","modified":"2026-01-06T00:15:45.334Z"},"maintainers":[{"name":"anders94","email":"anders-npmjs@evantide.com"}],"description":"A lightweight Sign In With Ethereum TypeScript module.","keywords":[],"author":{"name":"Anders Brownworth"},"license":"MIT","readme":"# @anders94/siwe\n\nA lightweight TypeScript implementation of [Sign-In with Ethereum (EIP-4361)](https://eips.ethereum.org/EIPS/eip-4361).\n\n## Why this library?\n\nMost SIWE implementations depend on heavy Ethereum libraries like ethers.js or viem. This library uses only [@noble/secp256k1](https://github.com/paulmillr/noble-secp256k1) and [@noble/hashes](https://github.com/paulmillr/noble-hashes) for cryptographic operations, resulting in a much smaller bundle size for applications that don't need a full Ethereum library.\n\n## Installation\n\n```bash\nnpm install @anders94/siwe\n```\n\n## Usage\n\n### Creating a SIWE message\n\n```typescript\nimport { SiweMessage } from '@anders94/siwe';\n\nconst message = new SiweMessage({\n  domain: 'myapp.com',\n  address: '0x1234567890123456789012345678901234567890',\n  statement: 'Sign in to My App',\n  uri: 'https://myapp.com',\n  version: '1',\n  chainId: 1,\n  nonce: 'randomNonce123',\n  issuedAt: new Date().toISOString(),\n  expirationTime: new Date(Date.now() + 3600000).toISOString(), // optional\n  notBefore: new Date().toISOString(), // optional\n  requestId: 'request-123', // optional\n  resources: ['https://myapp.com/api'] // optional\n});\n\n// Get the message string to be signed\nconst messageString = message.prepareMessage();\n```\n\n### Parsing a SIWE message\n\n```typescript\nimport { SiweMessage } from '@anders94/siwe';\n\nconst messageString = `myapp.com wants you to sign in with your Ethereum account:\n0x1234567890123456789012345678901234567890\n\nSign in to My App\n\nURI: https://myapp.com\nVersion: 1\nChain ID: 1\nNonce: randomNonce123\nIssued At: 2024-01-01T00:00:00.000Z`;\n\nconst message = SiweMessage.fromString(messageString);\n```\n\n### Validating a signature\n\n```typescript\nimport { SiweMessage } from '@anders94/siwe';\n\nconst message = new SiweMessage({\n  domain: 'myapp.com',\n  address: userAddress,\n  uri: 'https://myapp.com',\n  version: '1',\n  chainId: 1,\n  nonce: 'randomNonce123',\n  issuedAt: new Date().toISOString()\n});\n\ntry {\n  // Validates signature and checks expiration/notBefore times\n  await message.validate(signature);\n  console.log('Signature valid!');\n} catch (error) {\n  console.error('Validation failed:', error.message);\n}\n```\n\n### Low-level signature verification\n\n```typescript\nimport { checkSignature } from '@anders94/siwe';\n\nconst isValid = await checkSignature(message, signature, expectedAddress);\n```\n\n## API\n\n### `SiweMessage`\n\n#### Constructor Options\n\n| Property | Type | Required | Description |\n|----------|------|----------|-------------|\n| `domain` | `string` | Yes | The domain requesting the sign-in |\n| `address` | `string` | Yes | Ethereum address (0x-prefixed) |\n| `uri` | `string` | Yes | URI of the resource |\n| `version` | `string` | Yes | SIWE version (typically \"1\") |\n| `chainId` | `number` | Yes | EIP-155 chain ID |\n| `nonce` | `string` | Yes | Randomized token for replay protection |\n| `issuedAt` | `string` | Yes | ISO 8601 timestamp |\n| `statement` | `string` | No | Human-readable message |\n| `expirationTime` | `string` | No | ISO 8601 expiration time |\n| `notBefore` | `string` | No | ISO 8601 time before which message is invalid |\n| `requestId` | `string` | No | Request identifier |\n| `resources` | `string[]` | No | List of resource URIs |\n\n#### Methods\n\n- `prepareMessage(): string` - Returns the EIP-4361 formatted message string\n- `toMessage(): string` - Alias for `prepareMessage()`\n- `validate(signature: string): Promise<SiweMessage>` - Validates signature and time constraints\n- `static fromString(str: string): SiweMessage` - Parses an EIP-4361 message string\n\n### `checkSignature`\n\n```typescript\nfunction checkSignature(\n  message: string,\n  signature: string,\n  expectedAddress: string\n): Promise<boolean>\n```\n\nLow-level function to verify an Ethereum signature matches an expected address.\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-5c55490841e11f386006629dab42a8f1"}