-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: added example for derive-secret
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# derive secret | ||
|
||
```bash | ||
npx @phala/fn build index.ts | ||
npx @phala/fn run dist/index.js -a 00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000568656c6c6f000000000000000000000000000000000000000000000000000000 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import '@phala/pink-env' | ||
import { encodeAbiParameters, decodeAbiParameters } from 'viem' | ||
|
||
type Hex = `0x${string}` | ||
|
||
export default function main(payload: Hex) { | ||
const [requestId, seed] = decodeAbiParameters( | ||
[{ type: 'uint256' }, { type: 'bytes' }], | ||
payload | ||
) | ||
const secret = pink.deriveSecret(seed) | ||
|
||
return encodeAbiParameters( | ||
[{ type: 'uint256' }, { type: 'string' }], | ||
[ | ||
requestId, | ||
secret.toString() | ||
] | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "derive-secret", | ||
"private": true, | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@phala/pink-env": "^1.0.11" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.2.2", | ||
"@phala/fn": "file:../../" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"resolveJsonModule": true | ||
} | ||
} |