icp-attestation-principal.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
11 days ago
| 1 | #!/usr/bin/env node |
| 2 | /** |
| 3 | * Utility: derive the ICP Principal from ICP_ATTESTATION_KEY. |
| 4 | * |
| 5 | * Usage: |
| 6 | * ICP_ATTESTATION_KEY=<hex> node scripts/icp-attestation-principal.mjs |
| 7 | * |
| 8 | * Or with .env loaded: |
| 9 | * node scripts/icp-attestation-principal.mjs |
| 10 | * |
| 11 | * Output: the Principal text that must be passed to the attestation canister's |
| 12 | * setAuthorizedCallers method after deploy: |
| 13 | * |
| 14 | * dfx canister call attestation setAuthorizedCallers \ |
| 15 | * '(vec { principal "<printed-principal>" })' --network ic |
| 16 | */ |
| 17 | |
| 18 | import { existsSync, readFileSync } from 'fs'; |
| 19 | import { resolve, dirname } from 'path'; |
| 20 | import { fileURLToPath } from 'url'; |
| 21 | |
| 22 | const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 23 | const envPath = resolve(__dirname, '..', '.env'); |
| 24 | if (existsSync(envPath)) { |
| 25 | const lines = readFileSync(envPath, 'utf8').split('\n'); |
| 26 | for (const line of lines) { |
| 27 | const trimmed = line.trim(); |
| 28 | if (!trimmed || trimmed.startsWith('#')) continue; |
| 29 | const eqIdx = trimmed.indexOf('='); |
| 30 | if (eqIdx < 0) continue; |
| 31 | const key = trimmed.slice(0, eqIdx).trim(); |
| 32 | let val = trimmed.slice(eqIdx + 1).trim(); |
| 33 | if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) { |
| 34 | val = val.slice(1, -1); |
| 35 | } |
| 36 | if (!process.env[key]) process.env[key] = val; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | const keyHex = process.env.ICP_ATTESTATION_KEY; |
| 41 | if (!keyHex || keyHex.trim().length < 64) { |
| 42 | console.error( |
| 43 | 'Error: ICP_ATTESTATION_KEY must be set (64-char hex string, 32 bytes).\n' + |
| 44 | 'Generate one: openssl rand -hex 32\n' + |
| 45 | 'Set in .env or export before running.', |
| 46 | ); |
| 47 | process.exit(1); |
| 48 | } |
| 49 | |
| 50 | const { Secp256k1KeyIdentity } = await import('@icp-sdk/core/identity/secp256k1'); |
| 51 | |
| 52 | const seed = Uint8Array.from(Buffer.from(keyHex.trim(), 'hex')); |
| 53 | const identity = Secp256k1KeyIdentity.fromSecretKey(seed); |
| 54 | const principal = identity.getPrincipal().toText(); |
| 55 | |
| 56 | console.log('Gateway identity Principal:'); |
| 57 | console.log(principal); |
| 58 | console.log(''); |
| 59 | console.log('After deploying the attestation canister, run:'); |
| 60 | console.log(''); |
| 61 | console.log( |
| 62 | ` cd hub/icp && dfx canister call attestation setAuthorizedCallers '(vec { principal "${principal}" })' --network ic`, |
| 63 | ); |
File History
4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
11 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
30 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91
fix: repair endpoint now sets has_active_subscription when …
Human
minor
⚠
50 days ago
sha256:6a102aafafdfe7e70a24f4e59740200f0ee713ce7915f1b53e9d4ba5ee8b4410
Initial Muse snapshot
Human
83 days ago