(opts: {
identity: string;
capability: Capability;
ttlSeconds?: number | null; // null/undefined = no expiry
note?: string;
path?: string;
})
| 76 | * Owner-granted mint path. Adds (or upgrades) an allowlist entry. |
| 77 | */ |
| 78 | export async function grantIdentity(opts: { |
| 79 | identity: string; |
| 80 | capability: Capability; |
| 81 | ttlSeconds?: number | null; // null/undefined = no expiry |
| 82 | note?: string; |
| 83 | path?: string; |
| 84 | }): Promise<Allowlist> { |
| 85 | const path = opts.path ?? defaultAllowlistPath(); |
| 86 | const allowlist = await loadAllowlist(path); |
| 87 | const existingIdx = allowlist.entries.findIndex(e => e.identity === opts.identity); |
| 88 | const expiresAt = opts.ttlSeconds && opts.ttlSeconds > 0 |
| 89 | ? new Date(Date.now() + opts.ttlSeconds * 1000).toISOString() |
| 90 | : null; |
| 91 | const newEntry: AllowlistEntry = { |
| 92 | identity: opts.identity, |
| 93 | capabilities: [opts.capability], |
| 94 | expires_at: expiresAt, |
| 95 | note: opts.note, |
| 96 | }; |
| 97 | if (existingIdx >= 0) { |
| 98 | allowlist.entries[existingIdx] = newEntry; |
| 99 | } else { |
| 100 | allowlist.entries.push(newEntry); |
| 101 | } |
| 102 | await saveAllowlist(allowlist, path); |
| 103 | return allowlist; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Revoke an identity from the allowlist. |
no test coverage detected