payid-attestation 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/index.ts +1 -0
- package/package.json +15 -0
- package/src/index.ts +2 -0
- package/src/types.ts +6 -0
- package/src/verify.ts +31 -0
- package/tsconfig.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# attestation
|
|
2
|
+
|
|
3
|
+
To install dependencies:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun install
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
To run:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun run index.ts
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This project was created using `bun init` in bun v1.2.21. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src";
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "payid-attestation",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "bun build src/verify.ts --outdir dist --target node"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/bun": "latest"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"typescript": "^5"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
package/src/verify.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ethers, keccak256, toUtf8Bytes, verifyMessage, toBeArray } from "ethers";
|
|
2
|
+
import type { Attestation } from "./types";
|
|
3
|
+
|
|
4
|
+
export function verifyAttestation(
|
|
5
|
+
payload: object,
|
|
6
|
+
proof: Attestation,
|
|
7
|
+
trustedIssuers: Set<string>
|
|
8
|
+
) {
|
|
9
|
+
const now = Math.floor(Date.now() / 1000);
|
|
10
|
+
|
|
11
|
+
if (!trustedIssuers.has(proof.issuer)) {
|
|
12
|
+
throw new Error("UNTRUSTED_ATTESTATION_ISSUER");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (proof.expiresAt < now) {
|
|
16
|
+
throw new Error("ATTESTATION_EXPIRED");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const hash = keccak256(
|
|
20
|
+
toUtf8Bytes(JSON.stringify(payload))
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const recovered = verifyMessage(
|
|
24
|
+
toBeArray(hash),
|
|
25
|
+
proof.signature
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
if (recovered.toLowerCase() !== proof.issuer.toLowerCase()) {
|
|
29
|
+
throw new Error("INVALID_ATTESTATION_SIGNATURE");
|
|
30
|
+
}
|
|
31
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
// Best practices
|
|
18
|
+
"strict": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedIndexedAccess": true,
|
|
22
|
+
"noImplicitOverride": true,
|
|
23
|
+
|
|
24
|
+
// Some stricter flags (disabled by default)
|
|
25
|
+
"noUnusedLocals": false,
|
|
26
|
+
"noUnusedParameters": false,
|
|
27
|
+
"noPropertyAccessFromIndexSignature": false
|
|
28
|
+
}
|
|
29
|
+
}
|