@@ -6,20 +6,25 @@ import { sepolia, foundry } from "viem/chains";
66import { importAbi } from "@/importAbi.js" ;
77import packageJson from "../package.json" with { type : "json" } ;
88import { exit } from "node:process" ;
9+ import { parseJwt } from "./oidc.js" ;
910
1011const COMMAND_NAME = "fcf" ;
1112const COMMAND_DESCRIPTION = "FCF CLI tool."
1213const VERSION = packageJson ?. version || "v0.0.1" ;
1314
15+ function die ( err : any ) : never {
16+ let error = "unknown error" ;
17+ if ( err instanceof Error ) error = err . message ;
18+ console . error ( `${ COMMAND_NAME } : ${ error } ; exiting.` )
19+ exit ( 1 ) ;
20+ }
21+
1422// import abi -> created by forge build
1523let abi : Abi | null = null ;
1624try {
1725 abi = importAbi ( ) ;
1826} catch ( err ) {
19- let error = "unknown error" ;
20- if ( err instanceof Error ) error = err . message ;
21- console . error ( `${ COMMAND_NAME } : ${ error } ; exiting.` )
22- exit ( 1 ) ;
27+ die ( err ) ;
2328}
2429
2530const RepoRegisteredEvent = parseAbiItem (
@@ -48,17 +53,32 @@ function clients() {
4853
4954program
5055 . command ( "register" )
51- . requiredOption ( "--repo-id <n>" , "GitHub repository_id" )
52- . requiredOption ( "--owner-id <n>" , "GitHub owner numeric id" )
56+ . requiredOption ( "--oidcToken <token>" , "GitHub's OIDC repository token" )
5357 // needs to be removed in prod or be a default
5458 . requiredOption ( "--contract <addr>" , "deployed RIK address" )
5559 . action ( async ( opts ) => {
5660 const { wallet, publicC, account } = clients ( ) ;
61+
62+ const jwt = ( ( ) => {
63+ try {
64+ return parseJwt ( opts . oidcToken ) ;
65+ } catch ( err ) {
66+ die ( err ) ;
67+ }
68+ } ) ( ) ;
69+
70+ const expectedAud = account . address . toLowerCase ( ) ;
71+ if ( jwt . payload . aud ?. toLowerCase ( ) !== expectedAud ) {
72+ die ( new Error ( `aud mismatch: want ${ expectedAud } , got ${ jwt . payload . aud } ` ) ) ;
73+ }
74+ const repoId = BigInt ( jwt . payload . repository_id ) ;
75+ const ownerId = BigInt ( jwt . payload . repository_owner_id ) ;
76+
5777 const hash = await wallet . writeContract ( {
5878 address : opts . contract as `0x${string } `,
5979 abi,
6080 functionName : "register" ,
61- args : [ BigInt ( opts . repoId ) , BigInt ( opts . ownerId ) ] ,
81+ args : [ repoId , ownerId ] ,
6282 account,
6383 } ) ;
6484 const r = await publicC . waitForTransactionReceipt ( { hash } ) ;
0 commit comments