@tryagentkey/runtime 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/README.md +16 -0
  2. package/index.mjs +58 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -35,3 +35,19 @@ Fails closed when the page origin differs or the form is ambiguous. Reports exac
35
35
  `GET self`, `POST heartbeat`, `GET pending`, `GET operations/<id>` (no ciphertext), `POST operations/<id>/claim`, `POST target-operations/<id>/claim`, `POST operations/<id>/complete {completed|failed|unknown}`, `POST target-support`, `POST targets`, `POST session/refresh`. All under `/v1/executor/`.
36
36
 
37
37
  Owner disabling the runtime stops new claims; poll `self()` and stop when it returns nothing.
38
+
39
+ ## Agent-created login proposals (0.1.1)
40
+
41
+ An enrolled executor hosting an open Glove session can stage an encrypted login proposal for its owner. The session binds the owner, requesting agent, and executor. These methods do not create a website account by themselves, approve a grant, or import a login into an owner vault.
42
+
43
+ - `ownerRecipientKey(sessionId)` fetches the session owner's published recipient key.
44
+ - `proposeCreatedLogin({sessionId, agentId, origin, username, title, password})` seals the credential to that key and stages a proposal. `agentId` must match the agent bound to the session. `origin` must be an exact HTTPS origin. It returns a proposal identifier and state, not the password.
45
+ - `proposalStatus(proposalId, sessionId)` reads its state.
46
+ - `confirmLoginProposal(proposalId, sessionId)` records confirmed account creation. Call only after the website outcome is verified.
47
+ - `markLoginProposalUncertain(proposalId, sessionId)` preserves an uncertain outcome for owner recovery. Do not blindly repeat signup.
48
+ - `retractLoginProposal(proposalId, sessionId)` retracts a staged proposal when appropriate.
49
+ - `proposeLogin({sessionId, origin, recipientKeyId, ciphertext})` is the lower-level staging method for an already sealed envelope.
50
+
51
+ The exported `sealAgentLogin(login, scope, recipientPublicKeyB64)` helper uses an ephemeral X25519 key, HKDF-SHA256, and AES-256-GCM with the owner, agent, recipient-key identifier, and origin bound into authenticated data. The owner's recipient private key is needed to open the result. Server-side authorization and state checks still apply.
52
+
53
+ This runtime handles plaintext within the trusted executor process while sealing. Do not put a real password in a model prompt, tool result, log, or source file. A caller that passes a password string directly already has access to that string; this API alone does not hide it from that caller. Owner-vault import, backup, and device notification delivery are separate workflows and are not proved by staging or confirming a proposal.
package/index.mjs CHANGED
@@ -69,6 +69,28 @@ export async function openGrantEnvelope(encoded,scope,key){
69
69
  return {username:p.username,password:p.password};
70
70
  }
71
71
 
72
+ // Agent-created login envelope (AgentKey.agent-login.v1): byte-compatible
73
+ // port of apps/mobile/src/crypto.ts sealAgentLogin. Sealed to the owner's
74
+ // published recipient key; only the owner's private key opens it.
75
+ function agentLoginBinding(s){return enc.encode(['AgentKey.agent-login.v1',s.ownerID.toLowerCase(),s.agentID.toLowerCase(),s.recipientKeyID.toLowerCase(),s.origin].join('\n'));}
76
+ function agentLoginWire(s){return {ownerID:s.ownerID.toUpperCase(),agentID:s.agentID.toUpperCase(),recipientKeyID:s.recipientKeyID.toUpperCase(),origin:s.origin};}
77
+ export async function sealAgentLogin(login,scope,recipientPublicKeyB64){
78
+ if(!scope||!UUID.test(scope.ownerID)||!UUID.test(scope.agentID)||!UUID.test(scope.recipientKeyID)||!validOrigin(scope.origin))throw new RuntimeError('invalid_request');
79
+ if(!login||typeof login.title!=='string'||typeof login.username!=='string'||typeof login.password!=='string'||!login.password)throw new RuntimeError('invalid_request');
80
+ const recipient=await crypto.subtle.importKey('raw',b64d(recipientPublicKeyB64),{name:'X25519'},false,[]);
81
+ const eph=await crypto.subtle.generateKey({name:'X25519'},false,['deriveBits']);
82
+ const shared=await crypto.subtle.deriveBits({name:'X25519',public:recipient},eph.privateKey,256);
83
+ const binding=agentLoginBinding(scope);
84
+ const hk=await crypto.subtle.importKey('raw',shared,{name:'HKDF'},false,['deriveKey']);
85
+ const key=await crypto.subtle.deriveKey({name:'HKDF',hash:'SHA-256',salt:enc.encode('AgentKey.agent-login.v1'),info:binding},hk,{name:'AES-GCM',length:256},false,['encrypt']);
86
+ const plain=enc.encode(JSON.stringify({scope:agentLoginWire(scope),title:login.title,username:login.username,password:login.password}));
87
+ if(plain.length>15000)throw new RuntimeError('invalid_request');
88
+ const iv=crypto.getRandomValues(new Uint8Array(12));
89
+ const ct=new Uint8Array(await crypto.subtle.encrypt({name:'AES-GCM',iv,additionalData:binding},key,plain));
90
+ const sealed=new Uint8Array(12+ct.length);sealed.set(iv);sealed.set(ct,12);
91
+ const pub=await crypto.subtle.exportKey('raw',eph.publicKey);
92
+ return b64e(enc.encode(JSON.stringify({version:1,scope:agentLoginWire(scope),ephemeralPublicKey:b64e(new Uint8Array(pub)),sealed:b64e(sealed)})));
93
+ }
72
94
  export class AgentKeyRuntime{
73
95
  constructor({baseURL='https://agentkey.waiwiser.com/api/public/agentkey-api',key,session,onSession,fetchImpl=fetch}){Object.assign(this,{baseURL,key,session,onSession,fetchImpl});}
74
96
  async #call(method,path,body,bearer){
@@ -130,6 +152,41 @@ export class AgentKeyRuntime{
130
152
  // closed unless the page's current origin exactly matches the grant origin.
131
153
  // Reports exactly one outcome; a submitted form is reported as 'unknown'
132
154
  // unless verify() confirms the signed-in state.
155
+ // Agent-created logins (glove signup-and-save). The runtime seals to the
156
+ // owner's current recipient key; the server only ever stores ciphertext.
157
+ // Executor-scoped proposal lifecycle. Every call is bound to the glove
158
+ // session the runtime is hosting: the server derives owner and agent from
159
+ // the session's immutable binding, so a caller can never name them.
160
+ async ownerRecipientKey(sessionId){
161
+ if(!UUID.test(sessionId))throw new RuntimeError('invalid_request');
162
+ const r=await this.#call('POST','/v1/executor/glove/proposals/key',{session_id:sessionId},await this.#token());
163
+ if(!r||!UUID.test(r.owner_id)||!UUID.test(r.agent_id)||!UUID.test(r.recipient_key_id)||typeof r.public_key!=='string'||r.public_key.length!==44)throw new RuntimeError('invalid_response');
164
+ return {ownerId:r.owner_id,agentId:r.agent_id,keyId:r.recipient_key_id,publicKey:r.public_key};
165
+ }
166
+ async proposeLogin({sessionId,origin,recipientKeyId,ciphertext}){
167
+ if(!UUID.test(sessionId)||!UUID.test(recipientKeyId)||!validOrigin(origin)||typeof ciphertext!=='string'||ciphertext.length<100||ciphertext.length>40000)throw new RuntimeError('invalid_request');
168
+ const r=await this.#call('POST','/v1/executor/glove/proposals',{session_id:sessionId,origin,recipient_key_id:recipientKeyId,ciphertext},await this.#token());
169
+ if(!r||!UUID.test(r.proposal_id)||typeof r.state!=='string')throw new RuntimeError('invalid_response');
170
+ return {proposalId:r.proposal_id,status:r.state};
171
+ }
172
+ async proposalStatus(id,sessionId){if(!UUID.test(id)||!UUID.test(sessionId))throw new RuntimeError('invalid_request');const r=await this.#call('POST','/v1/executor/glove/proposals/'+id+'/status',{session_id:sessionId},await this.#token());if(!r||typeof r.state!=='string')throw new RuntimeError('invalid_response');return r.state;}
173
+ async markLoginProposalUncertain(id,sessionId){if(!UUID.test(id)||!UUID.test(sessionId))throw new RuntimeError('invalid_request');return this.#call('POST','/v1/executor/glove/proposals/'+id+'/uncertain',{session_id:sessionId},await this.#token());}
174
+ async confirmLoginProposal(id,sessionId){if(!UUID.test(id)||!UUID.test(sessionId))throw new RuntimeError('invalid_request');return this.#call('POST','/v1/executor/glove/proposals/'+id+'/confirm',{session_id:sessionId},await this.#token());}
175
+ async retractLoginProposal(id,sessionId){if(!UUID.test(id)||!UUID.test(sessionId))throw new RuntimeError('invalid_request');return this.#call('POST','/v1/executor/glove/proposals/'+id+'/retract',{session_id:sessionId},await this.#token());}
176
+ // Seal a generated signup credential to the owner and stage it BEFORE the
177
+ // signup is committed. agentId must be the agent the session was redeemed
178
+ // for; the owner verifies the sealed scope against the proposal row, so a
179
+ // wrong agent id fails closed at import. Returns the durable proposal id;
180
+ // the credential itself is never returned, logged or sent anywhere else.
181
+ async proposeCreatedLogin({sessionId,agentId,origin,username,title,password}){
182
+ if(!UUID.test(sessionId)||!UUID.test(agentId))throw new RuntimeError('invalid_request');
183
+ if(typeof username!=='string'||username.length>200)throw new RuntimeError('invalid_request');
184
+ if(title!==undefined&&(typeof title!=='string'||title.length>120))throw new RuntimeError('invalid_request');
185
+ const k=await this.ownerRecipientKey(sessionId);
186
+ if(k.agentId.toLowerCase()!==agentId.toLowerCase())throw new RuntimeError('scope_mismatch');
187
+ const ciphertext=await sealAgentLogin({title:title??'',username,password},{ownerID:k.ownerId,agentID:agentId,recipientKeyID:k.keyId,origin},k.publicKey);
188
+ return this.proposeLogin({sessionId,origin,recipientKeyId:k.keyId,ciphertext});
189
+ }
133
190
  async fillOperation(operationId,page,{usernameSelector='input[autocomplete="username"],input[type="email"],input[name*="user" i],input[name*="email" i]',passwordSelector='input[type="password"]',submit=true,verify,targetBound=false,gloveSessionId,onSecret}={}){
134
191
  if(!UUID.test(operationId)||(gloveSessionId!==undefined&&(!UUID.test(gloveSessionId)||targetBound)))throw new RuntimeError('invalid_request');
135
192
  if(verify!==undefined&&typeof verify!=='function')throw new RuntimeError('invalid_verification');
@@ -166,3 +223,4 @@ export class AgentKeyRuntime{
166
223
  return {operation_id:operationId,outcome,submitted,verification,...(failure?{code:'submission_unconfirmed'}:{})};
167
224
  }
168
225
  }
226
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryagentkey/runtime",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "author": "AgentKey, Inc.",
5
5
  "type": "module",
6
6
  "main": "index.mjs",