@passport-agent/sdk 0.0.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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=agent-passport.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-passport.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/agent-passport.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,109 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { AgentPassport } from '../agent-passport.js';
3
+ import { PassportIssuer } from '@passport-agent/core';
4
+ describe('AgentPassport SDK', () => {
5
+ function createWithIssuer() {
6
+ const issuer = new PassportIssuer();
7
+ const passport = AgentPassport.issue({
8
+ principal: 'user:alice@test.com',
9
+ agent: 'agent:booking-bot',
10
+ permissions: ['calendar:read', 'calendar:write', 'email:send'],
11
+ limits: { maxSpend: 500 },
12
+ expiresIn: 3600_000,
13
+ }, issuer);
14
+ return { passport, issuer };
15
+ }
16
+ describe('issue', () => {
17
+ it('creates a passport with correct properties', () => {
18
+ const { passport } = createWithIssuer();
19
+ expect(passport.principal).toBe('user:alice@test.com');
20
+ expect(passport.agent).toBe('agent:booking-bot');
21
+ expect(passport.permissions).toEqual(['calendar:read', 'calendar:write', 'email:send']);
22
+ expect(passport.parentId).toBeNull();
23
+ expect(passport.id).toBeTruthy();
24
+ });
25
+ it('serializes to JSON', () => {
26
+ const { passport } = createWithIssuer();
27
+ const json = passport.toJSON();
28
+ expect(json.principal).toBe('user:alice@test.com');
29
+ expect(json.agent).toBe('agent:booking-bot');
30
+ expect(json.expiresAt).toBeTruthy();
31
+ });
32
+ });
33
+ describe('authorize', () => {
34
+ it('allows permitted actions', () => {
35
+ const { passport } = createWithIssuer();
36
+ const result = passport.authorize('calendar:read');
37
+ expect(result.allowed).toBe(true);
38
+ });
39
+ it('throws PassportDeniedError for unpermitted actions', () => {
40
+ const { passport } = createWithIssuer();
41
+ expect(() => passport.authorize('admin:delete')).toThrow('denied');
42
+ });
43
+ it('tryAuthorize returns result without throwing', () => {
44
+ const { passport } = createWithIssuer();
45
+ const result = passport.tryAuthorize('admin:delete');
46
+ expect(result.allowed).toBe(false);
47
+ });
48
+ it('tracks spend across calls', () => {
49
+ const { passport } = createWithIssuer();
50
+ passport.authorize('calendar:write', 200);
51
+ passport.authorize('calendar:write', 200);
52
+ expect(() => passport.authorize('calendar:write', 200)).toThrow('exceeds');
53
+ });
54
+ });
55
+ describe('delegate', () => {
56
+ it('creates narrowed child passport', () => {
57
+ const { passport } = createWithIssuer();
58
+ const child = passport.delegate({
59
+ agent: 'agent:email-helper',
60
+ permissions: ['email:send'],
61
+ limits: { maxSpend: 50 },
62
+ });
63
+ expect(child.agent).toBe('agent:email-helper');
64
+ expect(child.permissions).toEqual(['email:send']);
65
+ expect(child.parentId).toBe(passport.id);
66
+ expect(child.principal).toBe('user:alice@test.com');
67
+ });
68
+ it('throws PassportDelegationError on escalation', () => {
69
+ const { passport } = createWithIssuer();
70
+ expect(() => passport.delegate({
71
+ agent: 'agent:evil',
72
+ permissions: ['admin:nuke'],
73
+ })).toThrow('subset');
74
+ });
75
+ it('child can authorize within its scope', () => {
76
+ const { passport } = createWithIssuer();
77
+ const child = passport.delegate({
78
+ agent: 'agent:email-helper',
79
+ permissions: ['email:send'],
80
+ });
81
+ expect(child.tryAuthorize('email:send').allowed).toBe(true);
82
+ expect(child.tryAuthorize('calendar:read').allowed).toBe(false);
83
+ });
84
+ });
85
+ describe('revoke', () => {
86
+ it('revokes passport and all children', () => {
87
+ const { passport } = createWithIssuer();
88
+ const child = passport.delegate({
89
+ agent: 'agent:helper',
90
+ permissions: ['email:send'],
91
+ });
92
+ const revoked = passport.revoke();
93
+ expect(revoked).toHaveLength(2);
94
+ expect(child.tryAuthorize('email:send').allowed).toBe(false);
95
+ });
96
+ });
97
+ describe('audit', () => {
98
+ it('records all authorize calls', () => {
99
+ const { passport } = createWithIssuer();
100
+ passport.authorize('calendar:read');
101
+ passport.tryAuthorize('admin:delete');
102
+ const log = passport.auditLog;
103
+ expect(log).toHaveLength(2);
104
+ expect(log[0].allowed).toBe(true);
105
+ expect(log[1].allowed).toBe(false);
106
+ });
107
+ });
108
+ });
109
+ //# sourceMappingURL=agent-passport.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-passport.test.js","sourceRoot":"","sources":["../../src/__tests__/agent-passport.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,SAAS,gBAAgB;QACvB,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAClC;YACE,SAAS,EAAE,qBAAqB;YAChC,KAAK,EAAE,mBAAmB;YAC1B,WAAW,EAAE,CAAC,eAAe,EAAE,gBAAgB,EAAE,YAAY,CAAC;YAC9D,MAAM,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE;YACzB,SAAS,EAAE,QAAQ;SACpB,EACD,MAAM,CACP,CAAC;QACF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;QACrB,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;YACpD,MAAM,EAAE,QAAQ,EAAE,GAAG,gBAAgB,EAAE,CAAC;YACxC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;YACvD,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACjD,MAAM,CAAC,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CAAC,YAAY,CAAC;aAC5B,CAAC,CAAC;YAEH,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;YAClC,MAAM,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAChC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;QACrB,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;YACrC,MAAM,EAAE,QAAQ,EAAE,GAAG,gBAAgB,EAAE,CAAC;YACxC,QAAQ,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;YACpC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;YAEtC,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC;YAC9B,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC5B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import type { AuthorizeResult, AuditEntry } from '@passport-agent/core';
2
+ import { PassportIssuer } from '@passport-agent/core';
3
+ export interface IssueConfig {
4
+ principal: string;
5
+ agent: string;
6
+ permissions: string[];
7
+ limits?: {
8
+ maxSpend: number;
9
+ currency?: string;
10
+ };
11
+ expiresIn?: number;
12
+ }
13
+ export interface DelegateConfig {
14
+ agent: string;
15
+ permissions: string[];
16
+ limits?: {
17
+ maxSpend: number;
18
+ currency?: string;
19
+ };
20
+ expiresIn?: number;
21
+ }
22
+ export declare class AgentPassport {
23
+ private signed;
24
+ private issuer;
25
+ private constructor();
26
+ static issue(config: IssueConfig, issuer?: PassportIssuer): AgentPassport;
27
+ authorize(action: string, spendAmount?: number): AuthorizeResult;
28
+ tryAuthorize(action: string, spendAmount?: number): AuthorizeResult;
29
+ delegate(config: DelegateConfig): AgentPassport;
30
+ revoke(): string[];
31
+ get id(): string;
32
+ get principal(): string;
33
+ get agent(): string;
34
+ get permissions(): string[];
35
+ get expiresAt(): Date;
36
+ get parentId(): string | null;
37
+ get auditLog(): AuditEntry[];
38
+ toJSON(): {
39
+ id: string;
40
+ principal: string;
41
+ agent: string;
42
+ permissions: string[];
43
+ expiresAt: string;
44
+ parentId: string | null;
45
+ };
46
+ }
47
+ export declare class PassportDeniedError extends Error {
48
+ readonly action: string;
49
+ readonly passportId: string;
50
+ constructor(action: string, reason: string, passportId: string);
51
+ }
52
+ export declare class PassportDelegationError extends Error {
53
+ readonly targetAgent: string;
54
+ readonly passportId: string;
55
+ constructor(targetAgent: string, reason: string, passportId: string);
56
+ }
57
+ //# sourceMappingURL=agent-passport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-passport.d.ts","sourceRoot":"","sources":["../src/agent-passport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,eAAe,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WA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AU,EAAE,MAAM,CAAC;gBAEhB,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CASpE"}
@@ -0,0 +1,103 @@
1
+ import { getDefaultAuthority } from './authority.js';
2
+ export class AgentPassport {
3
+ signed;
4
+ issuer;
5
+ constructor(signed, issuer) {
6
+ this.signed = signed;
7
+ this.issuer = issuer;
8
+ }
9
+ static issue(config, issuer) {
10
+ const authority = issuer ?? getDefaultAuthority();
11
+ const signed = authority.issue({
12
+ principal: config.principal,
13
+ agent: config.agent,
14
+ permissions: config.permissions,
15
+ limits: config.limits,
16
+ expiresIn: config.expiresIn,
17
+ });
18
+ return new AgentPassport(signed, authority);
19
+ }
20
+ authorize(action, spendAmount = 0) {
21
+ const result = this.issuer.authorize(this.signed, action, spendAmount);
22
+ if (!result.allowed) {
23
+ const err = new PassportDeniedError(action, result.reason ?? 'Unknown reason', this.id);
24
+ throw err;
25
+ }
26
+ return result;
27
+ }
28
+ tryAuthorize(action, spendAmount = 0) {
29
+ return this.issuer.authorize(this.signed, action, spendAmount);
30
+ }
31
+ delegate(config) {
32
+ try {
33
+ const childSigned = this.issuer.delegate(this.signed, {
34
+ agent: config.agent,
35
+ permissions: config.permissions,
36
+ limits: config.limits,
37
+ expiresIn: config.expiresIn,
38
+ });
39
+ return new AgentPassport(childSigned, this.issuer);
40
+ }
41
+ catch (e) {
42
+ const msg = e instanceof Error ? e.message : String(e);
43
+ throw new PassportDelegationError(config.agent, msg, this.id);
44
+ }
45
+ }
46
+ revoke() {
47
+ return this.issuer.revoke(this.id);
48
+ }
49
+ get id() {
50
+ return this.signed.payload.id;
51
+ }
52
+ get principal() {
53
+ return this.signed.payload.principal;
54
+ }
55
+ get agent() {
56
+ return this.signed.payload.sub;
57
+ }
58
+ get permissions() {
59
+ return this.signed.payload.permissions.map((p) => p.action);
60
+ }
61
+ get expiresAt() {
62
+ return new Date(this.signed.payload.exp);
63
+ }
64
+ get parentId() {
65
+ return this.signed.payload.parentId;
66
+ }
67
+ get auditLog() {
68
+ return this.issuer.audit.getByPassport(this.id);
69
+ }
70
+ toJSON() {
71
+ return {
72
+ id: this.id,
73
+ principal: this.principal,
74
+ agent: this.agent,
75
+ permissions: this.permissions,
76
+ expiresAt: this.expiresAt.toISOString(),
77
+ parentId: this.parentId,
78
+ };
79
+ }
80
+ }
81
+ export class PassportDeniedError extends Error {
82
+ action;
83
+ passportId;
84
+ constructor(action, reason, passportId) {
85
+ super(`Action "${action}" denied for passport ${passportId.slice(0, 8)}...: ${reason}\n` +
86
+ ` Fix: Check that the passport includes permission for "${action}".`);
87
+ this.name = 'PassportDeniedError';
88
+ this.action = action;
89
+ this.passportId = passportId;
90
+ }
91
+ }
92
+ export class PassportDelegationError extends Error {
93
+ targetAgent;
94
+ passportId;
95
+ constructor(targetAgent, reason, passportId) {
96
+ super(`Cannot delegate to "${targetAgent}" from passport ${passportId.slice(0, 8)}...: ${reason}\n` +
97
+ ` Fix: Ensure child permissions are a subset of parent, and spend limits don't exceed parent's remaining budget.`);
98
+ this.name = 'PassportDelegationError';
99
+ this.targetAgent = targetAgent;
100
+ this.passportId = passportId;
101
+ }
102
+ }
103
+ //# sourceMappingURL=agent-passport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-passport.js","sourceRoot":"","sources":["../src/agent-passport.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAiBrD,MAAM,OAAO,aAAa;IAChB,MAAM,CAAiB;IACvB,MAAM,CAAiB;IAE/B,YAAoB,MAAsB,EAAE,MAAsB;QAChE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAmB,EAAE,MAAuB;QACvD,MAAM,SAAS,GAAG,MAAM,IAAI,mBAAmB,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG,SAAS,C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B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YACvC,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;IACJ,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,MAAM,CAAS;IACf,UAAU,CAAS;IAE5B,YAAY,MAAc,EAAE,MAAc,EAAE,UAAkB;QAC5D,KAAK,CACH,WAAW,MAAM,yBAAyB,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,MAAM,IAAI;YAClF,2DAA2D,MAAM,IAAI,CACtE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACvC,WAAW,CAAS;IACpB,UAAU,CAAS;IAE5B,YAAY,WAAmB,EAAE,MAAc,EAAE,UAAkB;QACjE,KAAK,CACH,uBAAuB,WAAW,mBAAmB,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,MAAM,IAAI;YAC7F,kHAAkH,CACnH,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import { PassportIssuer } from '@passport-agent/core';
2
+ export interface AuthorityConfig {
3
+ issuer?: string;
4
+ }
5
+ export declare function createPassportAuthority(config?: AuthorityConfig): PassportIssuer;
6
+ export declare function getDefaultAuthority(): PassportIssuer;
7
+ //# sourceMappingURL=authority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.d.ts","sourceRoot":"","sources":["../src/authority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,wBAAgB,uBAAuB,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,cAAc,CAMhF;AAED,wBAAgB,mBAAmB,IAAI,cAAc,CAKpD"}
@@ -0,0 +1,16 @@
1
+ import { PassportIssuer } from '@passport-agent/core';
2
+ let defaultAuthority = null;
3
+ export function createPassportAuthority(config) {
4
+ const authority = new PassportIssuer();
5
+ if (!defaultAuthority) {
6
+ defaultAuthority = authority;
7
+ }
8
+ return authority;
9
+ }
10
+ export function getDefaultAuthority() {
11
+ if (!defaultAuthority) {
12
+ defaultAuthority = new PassportIssuer();
13
+ }
14
+ return defaultAuthority;
15
+ }
16
+ //# sourceMappingURL=authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.js","sourceRoot":"","sources":["../src/authority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAMtD,IAAI,gBAAgB,GAA0B,IAAI,CAAC;AAEnD,MAAM,UAAU,uBAAuB,CAAC,MAAwB;IAC9D,MAAM,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC;IACvC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,gBAAgB,GAAG,SAAS,CAAC;IAC/B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,gBAAgB,GAAG,IAAI,cAAc,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { AgentPassport } from './agent-passport.js';
2
+ export { createPassportAuthority } from './authority.js';
3
+ export type { AuthorityConfig } from './authority.js';
4
+ export type { Permission, SpendLimit, PassportPayload, SignedPassport, AuthorizeResult, AuditEntry, } from '@passport-agent/core';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,UAAU,GACX,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { AgentPassport } from './agent-passport.js';
2
+ export { createPassportAuthority } from './authority.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@passport-agent/sdk",
3
+ "version": "0.0.1",
4
+ "description": "The Stripe for agent authorization — give every AI agent a cryptographically verifiable passport",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "test": "vitest run",
17
+ "lint": "tsc --noEmit"
18
+ },
19
+ "files": ["dist"],
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/priyansh-x/passport-agent",
24
+ "directory": "packages/sdk"
25
+ },
26
+ "dependencies": {
27
+ "@passport-agent/core": "workspace:*"
28
+ },
29
+ "devDependencies": {
30
+ "vitest": "^3.0.0"
31
+ }
32
+ }