@towns-labs/agent 2.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.
- package/README.md +151 -0
- package/dist/agent.d.ts +480 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +1758 -0
- package/dist/agent.js.map +1 -0
- package/dist/agent.test.d.ts +2 -0
- package/dist/agent.test.d.ts.map +1 -0
- package/dist/agent.test.js +1315 -0
- package/dist/agent.test.js.map +1 -0
- package/dist/eventDedup.d.ts +73 -0
- package/dist/eventDedup.d.ts.map +1 -0
- package/dist/eventDedup.js +105 -0
- package/dist/eventDedup.js.map +1 -0
- package/dist/eventDedup.test.d.ts +2 -0
- package/dist/eventDedup.test.d.ts.map +1 -0
- package/dist/eventDedup.test.js +222 -0
- package/dist/eventDedup.test.js.map +1 -0
- package/dist/identity-types.d.ts +43 -0
- package/dist/identity-types.d.ts.map +1 -0
- package/dist/identity-types.js +2 -0
- package/dist/identity-types.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction-api.d.ts +61 -0
- package/dist/interaction-api.d.ts.map +1 -0
- package/dist/interaction-api.js +95 -0
- package/dist/interaction-api.js.map +1 -0
- package/dist/payments.d.ts +89 -0
- package/dist/payments.d.ts.map +1 -0
- package/dist/payments.js +144 -0
- package/dist/payments.js.map +1 -0
- package/dist/re-exports.d.ts +2 -0
- package/dist/re-exports.d.ts.map +1 -0
- package/dist/re-exports.js +2 -0
- package/dist/re-exports.js.map +1 -0
- package/dist/smart-account.d.ts +54 -0
- package/dist/smart-account.d.ts.map +1 -0
- package/dist/smart-account.js +132 -0
- package/dist/smart-account.js.map +1 -0
- package/dist/snapshot-getter.d.ts +21 -0
- package/dist/snapshot-getter.d.ts.map +1 -0
- package/dist/snapshot-getter.js +27 -0
- package/dist/snapshot-getter.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-types.js","sourceRoot":"","sources":["../src/identity-types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**************************************************************************
|
|
2
|
+
* This file is generated by running 🏕️ scripts/generate_sdk_index.sh 🏕️ *
|
|
3
|
+
**************************************************************************/
|
|
4
|
+
export * from './agent';
|
|
5
|
+
export * from './eventDedup';
|
|
6
|
+
export * from './identity-types';
|
|
7
|
+
export * from './interaction-api';
|
|
8
|
+
export * from './re-exports';
|
|
9
|
+
export * from './smart-account';
|
|
10
|
+
export * from './snapshot-getter';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;4EAE4E;AAC5E,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**************************************************************************
|
|
2
|
+
* This file is generated by running 🏕️ scripts/generate_sdk_index.sh 🏕️ *
|
|
3
|
+
**************************************************************************/
|
|
4
|
+
export * from './agent';
|
|
5
|
+
export * from './eventDedup';
|
|
6
|
+
export * from './identity-types';
|
|
7
|
+
export * from './interaction-api';
|
|
8
|
+
export * from './re-exports';
|
|
9
|
+
export * from './smart-account';
|
|
10
|
+
export * from './snapshot-getter';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;4EAE4E;AAC5E,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
|
+
import { InteractionRequestPayload, InteractionRequestPayload_Signature_SignatureType, InteractionRequestPayload_Signature_SignatureValidation, InteractionRequestPayload_Form_Component, type PlainMessage } from '@towns-labs/proto';
|
|
3
|
+
type EnumStringKeys<E> = Exclude<keyof E, number>;
|
|
4
|
+
type EnumToLowercase<E> = Lowercase<EnumStringKeys<E> & string>;
|
|
5
|
+
export type SignatureMethod = EnumToLowercase<typeof InteractionRequestPayload_Signature_SignatureType>;
|
|
6
|
+
export type SignatureValidation = EnumToLowercase<typeof InteractionRequestPayload_Signature_SignatureValidation>;
|
|
7
|
+
type ContentCase = NonNullable<InteractionRequestPayload['content']['case']>;
|
|
8
|
+
type ContentValue<C extends ContentCase> = Extract<InteractionRequestPayload['content'], {
|
|
9
|
+
case: C;
|
|
10
|
+
}>['value'];
|
|
11
|
+
type ComponentCase = NonNullable<InteractionRequestPayload_Form_Component['component']['case']>;
|
|
12
|
+
type ComponentValue<C extends ComponentCase> = Extract<InteractionRequestPayload_Form_Component['component'], {
|
|
13
|
+
case: C;
|
|
14
|
+
}>['value'];
|
|
15
|
+
type FlattenedComponent<C extends ComponentCase> = {
|
|
16
|
+
id: string;
|
|
17
|
+
type: C;
|
|
18
|
+
} & PlainMessage<ComponentValue<C>>;
|
|
19
|
+
export type FlattenedFormComponent = {
|
|
20
|
+
[C in ComponentCase]: FlattenedComponent<C>;
|
|
21
|
+
}[ComponentCase];
|
|
22
|
+
type FlattenedRequestBase = {
|
|
23
|
+
recipient?: Address;
|
|
24
|
+
};
|
|
25
|
+
export type FlattenedSignatureRequest = FlattenedRequestBase & {
|
|
26
|
+
type: 'signature';
|
|
27
|
+
} & Omit<PlainMessage<ContentValue<'signature'>>, 'type' | 'signatureValidation' | 'signerWallet'> & {
|
|
28
|
+
method: SignatureMethod;
|
|
29
|
+
signatureValidation?: SignatureValidation;
|
|
30
|
+
signerWallet: Address;
|
|
31
|
+
};
|
|
32
|
+
export type FlattenedFormRequest = FlattenedRequestBase & {
|
|
33
|
+
type: 'form';
|
|
34
|
+
} & Omit<PlainMessage<ContentValue<'form'>>, 'components'> & {
|
|
35
|
+
components: FlattenedFormComponent[];
|
|
36
|
+
};
|
|
37
|
+
type EVMContentValue = Extract<ContentValue<'transaction'>['content'], {
|
|
38
|
+
case: 'evm';
|
|
39
|
+
}>['value'];
|
|
40
|
+
export type EVMTransaction = Omit<PlainMessage<EVMContentValue>, 'to' | 'signerWallet'> & {
|
|
41
|
+
to: Address;
|
|
42
|
+
signerWallet?: Address;
|
|
43
|
+
};
|
|
44
|
+
export type FlattenedTransactionRequest = FlattenedRequestBase & {
|
|
45
|
+
type: 'transaction';
|
|
46
|
+
} & Omit<PlainMessage<ContentValue<'transaction'>>, 'content'> & {
|
|
47
|
+
tx: EVMTransaction;
|
|
48
|
+
};
|
|
49
|
+
export type FlattenedInteractionRequest = FlattenedSignatureRequest | FlattenedFormRequest | FlattenedTransactionRequest | FlattenedAddMemberRequest;
|
|
50
|
+
export type FlattenedAddMemberRequest = FlattenedRequestBase & {
|
|
51
|
+
type: 'addMember';
|
|
52
|
+
} & Omit<PlainMessage<ContentValue<'addMember'>>, 'userId'> & {
|
|
53
|
+
userId: Address;
|
|
54
|
+
};
|
|
55
|
+
export declare function signatureMethodToEnum(method: SignatureMethod): InteractionRequestPayload_Signature_SignatureType;
|
|
56
|
+
export declare function signatureValidationToEnum(validation: SignatureValidation): InteractionRequestPayload_Signature_SignatureValidation;
|
|
57
|
+
export declare function isFlattenedRequest(content: PlainMessage<InteractionRequestPayload['content']> | FlattenedInteractionRequest): content is FlattenedInteractionRequest;
|
|
58
|
+
export declare function flattenedComponentToPayload(component: FlattenedFormComponent): PlainMessage<InteractionRequestPayload_Form_Component>;
|
|
59
|
+
export declare function flattenedToPayloadContent(payload: FlattenedInteractionRequest): PlainMessage<InteractionRequestPayload['content']>;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=interaction-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interaction-api.d.ts","sourceRoot":"","sources":["../src/interaction-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EACH,yBAAyB,EACzB,iDAAiD,EACjD,uDAAuD,EACvD,wCAAwC,EACxC,KAAK,YAAY,EACpB,MAAM,mBAAmB,CAAA;AAK1B,KAAK,cAAc,CAAC,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;AAGjD,KAAK,eAAe,CAAC,CAAC,IAAI,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAA;AAG/D,MAAM,MAAM,eAAe,GAAG,eAAe,CACzC,OAAO,iDAAiD,CAC3D,CAAA;AAGD,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAC7C,OAAO,uDAAuD,CACjE,CAAA;AAGD,KAAK,WAAW,GAAG,WAAW,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAG5E,KAAK,YAAY,CAAC,CAAC,SAAS,WAAW,IAAI,OAAO,CAC9C,yBAAyB,CAAC,SAAS,CAAC,EACpC;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CACd,CAAC,OAAO,CAAC,CAAA;AAGV,KAAK,aAAa,GAAG,WAAW,CAAC,wCAAwC,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAG/F,KAAK,cAAc,CAAC,CAAC,SAAS,aAAa,IAAI,OAAO,CAClD,wCAAwC,CAAC,WAAW,CAAC,EACrD;IAAE,IAAI,EAAE,CAA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,EAAE,OAAO,CAAA;CACzB,CAAA;AAGD,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC7D,IAAI,EAAE,aAAa,CAAA;CACtB,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG;IACzD,EAAE,EAAE,cAAc,CAAA;CACrB,CAAA;AAEL,MAAM,MAAM,2BAA2B,GACjC,yBAAyB,GACzB,oBAAoB,GACpB,2BAA2B,GAC3B,yBAAyB,CAAA;AAE/B,MAAM,MAAM,yBAAyB,GAAG,oBAAoB,GAAG;IAC3D,IAAI,EAAE,WAAW,CAAA;CACpB,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG;IACtD,MAAM,EAAE,OAAO,CAAA;CAClB,CAAA;AAGL,wBAAgB,qBAAqB,CACjC,MAAM,EAAE,eAAe,GACxB,iDAAiD,CAQnD;AAED,wBAAgB,yBAAyB,CACrC,UAAU,EAAE,mBAAmB,GAChC,uDAAuD,CAQzD;AAGD,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,YAAY,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAC,GAAG,2BAA2B,GAC1F,OAAO,IAAI,2BAA2B,CAMxC;AAGD,wBAAgB,2BAA2B,CACvC,SAAS,EAAE,sBAAsB,GAClC,YAAY,CAAC,wCAAwC,CAAC,CAYxD;AAGD,wBAAgB,yBAAyB,CACrC,OAAO,EAAE,2BAA2B,GACrC,YAAY,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAC,CAoDpD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { InteractionRequestPayload_Signature_SignatureType, InteractionRequestPayload_Signature_SignatureValidation, } from '@towns-labs/proto';
|
|
2
|
+
import { checkNever } from '@towns-labs/sdk';
|
|
3
|
+
import { bin_fromHexString } from '@towns-labs/utils';
|
|
4
|
+
// Runtime conversion: lowercase string -> enum value
|
|
5
|
+
export function signatureMethodToEnum(method) {
|
|
6
|
+
const key = method.toUpperCase();
|
|
7
|
+
const result = InteractionRequestPayload_Signature_SignatureType[key];
|
|
8
|
+
if (result === undefined) {
|
|
9
|
+
throw new Error(`Invalid signature method: ${method}`);
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
export function signatureValidationToEnum(validation) {
|
|
14
|
+
const key = validation.toUpperCase();
|
|
15
|
+
const result = InteractionRequestPayload_Signature_SignatureValidation[key];
|
|
16
|
+
if (result === undefined) {
|
|
17
|
+
throw new Error(`Invalid signature validation: ${validation}`);
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
// Type guard to detect flattened vs original format
|
|
22
|
+
export function isFlattenedRequest(content) {
|
|
23
|
+
return ('type' in content &&
|
|
24
|
+
typeof content.type === 'string' &&
|
|
25
|
+
['signature', 'form', 'transaction', 'addMember'].includes(content.type));
|
|
26
|
+
}
|
|
27
|
+
// Convert flattened component to payload format
|
|
28
|
+
export function flattenedComponentToPayload(component) {
|
|
29
|
+
const { id, type } = component;
|
|
30
|
+
if (type === 'button') {
|
|
31
|
+
return { id, component: { case: 'button', value: { label: component.label } } };
|
|
32
|
+
}
|
|
33
|
+
if (type === 'textInput') {
|
|
34
|
+
return {
|
|
35
|
+
id,
|
|
36
|
+
component: { case: 'textInput', value: { placeholder: component.placeholder } },
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
checkNever(type, `Unknown component type: ${type}`);
|
|
40
|
+
}
|
|
41
|
+
// Convert flattened request to payload content
|
|
42
|
+
export function flattenedToPayloadContent(payload) {
|
|
43
|
+
switch (payload.type) {
|
|
44
|
+
case 'signature': {
|
|
45
|
+
const { type, method, signatureValidation, recipient, signerWallet, ...rest } = payload;
|
|
46
|
+
return {
|
|
47
|
+
case: 'signature',
|
|
48
|
+
value: {
|
|
49
|
+
...rest,
|
|
50
|
+
signerWallet,
|
|
51
|
+
type: signatureMethodToEnum(method),
|
|
52
|
+
signatureValidation: signatureValidation
|
|
53
|
+
? signatureValidationToEnum(signatureValidation)
|
|
54
|
+
: undefined,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
case 'form': {
|
|
59
|
+
const { type, components, recipient, ...rest } = payload;
|
|
60
|
+
return {
|
|
61
|
+
case: 'form',
|
|
62
|
+
value: {
|
|
63
|
+
...rest,
|
|
64
|
+
components: components.map(flattenedComponentToPayload),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
case 'transaction': {
|
|
69
|
+
const { type, recipient, tx, ...rest } = payload;
|
|
70
|
+
return {
|
|
71
|
+
case: 'transaction',
|
|
72
|
+
value: {
|
|
73
|
+
...rest,
|
|
74
|
+
content: {
|
|
75
|
+
case: 'evm',
|
|
76
|
+
value: tx,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
case 'addMember': {
|
|
82
|
+
const { type, recipient, userId, ...rest } = payload;
|
|
83
|
+
return {
|
|
84
|
+
case: 'addMember',
|
|
85
|
+
value: {
|
|
86
|
+
...rest,
|
|
87
|
+
userId: bin_fromHexString(userId),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
default:
|
|
92
|
+
checkNever(payload, `Unknown request type: ${payload.type}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=interaction-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interaction-api.js","sourceRoot":"","sources":["../src/interaction-api.ts"],"names":[],"mappings":"AAEA,OAAO,EAEH,iDAAiD,EACjD,uDAAuD,GAG1D,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAmGrD,qDAA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AO,EAAE;wBACL,IAAI,EAAE,KAAK;wBACX,KAAK,EAAE,EAAE;qBACZ;iBACJ;aACJ,CAAA;QACL,CAAC;QACD,KAAK,WAAW,CAAC,CAAC,CAAC;YACf,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;YACpD,OAAO;gBACH,IAAI,EAAE,WAAW;gBACjB,KAAK,EAAE;oBACH,GAAG,IAAI;oBACP,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC;iBACpC;aACJ,CAAA;QACL,CAAC;QACD;YACI,UAAU,CAAC,OAAO,EAAE,yBAA0B,OAA4B,CAAC,IAAI,EAAE,CAAC,CAAA;IAC1F,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
import type { BasePayload, AgentHandler } from './agent';
|
|
3
|
+
import type { Price, RouteConfig } from 'x402/types';
|
|
4
|
+
export declare const USDC_ADDRESSES: Record<number, Address>;
|
|
5
|
+
export interface PendingPayment {
|
|
6
|
+
command: string;
|
|
7
|
+
channelId: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
/** The eventId of the interaction request message (to delete after signing) */
|
|
10
|
+
interactionEventId: string;
|
|
11
|
+
event: BasePayload & {
|
|
12
|
+
command: string;
|
|
13
|
+
args: string[];
|
|
14
|
+
mentions: any[];
|
|
15
|
+
replyId: string | undefined;
|
|
16
|
+
threadId: string | undefined;
|
|
17
|
+
};
|
|
18
|
+
params: TransferAuthorizationParams;
|
|
19
|
+
}
|
|
20
|
+
export declare function chainIdToNetwork(chainId: number): 'base' | 'base-sepolia';
|
|
21
|
+
export declare function getUsdcAddress(chainId: number): Address;
|
|
22
|
+
export interface TransferAuthorizationParams {
|
|
23
|
+
from: Address;
|
|
24
|
+
to: Address;
|
|
25
|
+
value: bigint;
|
|
26
|
+
validAfter: bigint;
|
|
27
|
+
validBefore: bigint;
|
|
28
|
+
nonce: Hex;
|
|
29
|
+
chainId: number;
|
|
30
|
+
verifyingContract: Address;
|
|
31
|
+
}
|
|
32
|
+
export interface TypedData {
|
|
33
|
+
types: {
|
|
34
|
+
[key: string]: Array<{
|
|
35
|
+
name: string;
|
|
36
|
+
type: string;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
domain: {
|
|
40
|
+
name: string;
|
|
41
|
+
version: string;
|
|
42
|
+
chainId: number;
|
|
43
|
+
verifyingContract: Address;
|
|
44
|
+
};
|
|
45
|
+
primaryType: string;
|
|
46
|
+
message: {
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Generate a unique nonce for USDC authorization
|
|
52
|
+
* Uses crypto-safe random bytes
|
|
53
|
+
*/
|
|
54
|
+
export declare function generateNonce(): Hex;
|
|
55
|
+
/**
|
|
56
|
+
* Get validity window for authorization
|
|
57
|
+
* validAfter: current timestamp
|
|
58
|
+
* validBefore: current timestamp + 1 hour
|
|
59
|
+
*/
|
|
60
|
+
export declare function getValidityWindow(): {
|
|
61
|
+
validAfter: bigint;
|
|
62
|
+
validBefore: bigint;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Build EIP-712 typed data for USDC transferWithAuthorization signature request
|
|
66
|
+
* Synchronous version for sending to client - no contract calls needed
|
|
67
|
+
*/
|
|
68
|
+
export declare function buildTransferAuthorizationTypedDataForSigning(params: TransferAuthorizationParams): TypedData;
|
|
69
|
+
/**
|
|
70
|
+
* Simplified payment request builder
|
|
71
|
+
* Returns all data needed to track and verify the payment
|
|
72
|
+
*/
|
|
73
|
+
export declare function createPaymentRequest(handler: AgentHandler, event: BasePayload, chainId: number, fromAddress: Address, recipientAddress: Address, paymentConfig: RouteConfig, command: string): Promise<{
|
|
74
|
+
signatureId: string;
|
|
75
|
+
params: TransferAuthorizationParams;
|
|
76
|
+
eventId: string;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Parses a USDC price to atomic units (6 decimals).
|
|
80
|
+
* Handles dollar signs, commas, and decimal amounts.
|
|
81
|
+
* Only string and number inputs are supported.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* parseUSDCPrice("$1.00") // 1000000n
|
|
85
|
+
* parseUSDCPrice(1.50) // 1500000n
|
|
86
|
+
* parseUSDCPrice("$1,000.00") // 1000000000n
|
|
87
|
+
*/
|
|
88
|
+
export declare function parseUSDCPrice(price: Price): bigint;
|
|
89
|
+
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAGxC,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAGpD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAGlD,CAAA;AAED,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,+EAA+E;IAC/E,kBAAkB,EAAE,MAAM,CAAA;IAC1B,KAAK,EAAE,WAAW,GAAG;QACjB,OAAO,EAAE,MAAM,CAAA;QACf,IAAI,EAAE,MAAM,EAAE,CAAA;QACd,QAAQ,EAAE,GAAG,EAAE,CAAA;QACf,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;QAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;KAC/B,CAAA;IACD,MAAM,EAAE,2BAA2B,CAAA;CACtC;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CASzE;AAED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B;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAkBnD"}
|
package/dist/payments.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { keccak256 } from 'viem';
|
|
2
|
+
import { baseSepolia, base } from 'viem/chains';
|
|
3
|
+
import { InteractionRequestPayload_Signature_SignatureType } from '@towns-labs/proto';
|
|
4
|
+
export const USDC_ADDRESSES = {
|
|
5
|
+
[baseSepolia.id]: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
|
|
6
|
+
[base.id]: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
7
|
+
};
|
|
8
|
+
export function chainIdToNetwork(chainId) {
|
|
9
|
+
switch (chainId) {
|
|
10
|
+
case base.id:
|
|
11
|
+
return 'base';
|
|
12
|
+
case baseSepolia.id:
|
|
13
|
+
return 'base-sepolia';
|
|
14
|
+
default:
|
|
15
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function getUsdcAddress(chainId) {
|
|
19
|
+
const address = USDC_ADDRESSES[chainId];
|
|
20
|
+
if (!address) {
|
|
21
|
+
throw new Error(`USDC address not found for chain ID: ${chainId}`);
|
|
22
|
+
}
|
|
23
|
+
return address;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generate a unique nonce for USDC authorization
|
|
27
|
+
* Uses crypto-safe random bytes
|
|
28
|
+
*/
|
|
29
|
+
export function generateNonce() {
|
|
30
|
+
const randomBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
31
|
+
return keccak256(randomBytes);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get validity window for authorization
|
|
35
|
+
* validAfter: current timestamp
|
|
36
|
+
* validBefore: current timestamp + 1 hour
|
|
37
|
+
*/
|
|
38
|
+
export function getValidityWindow() {
|
|
39
|
+
const now = BigInt(Math.floor(Date.now() / 1000));
|
|
40
|
+
return {
|
|
41
|
+
validAfter: now,
|
|
42
|
+
validBefore: now + 3600n, // 1 hour
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build EIP-712 typed data for USDC transferWithAuthorization signature request
|
|
47
|
+
* Synchronous version for sending to client - no contract calls needed
|
|
48
|
+
*/
|
|
49
|
+
export function buildTransferAuthorizationTypedDataForSigning(params) {
|
|
50
|
+
return {
|
|
51
|
+
types: {
|
|
52
|
+
TransferWithAuthorization: [
|
|
53
|
+
{ name: 'from', type: 'address' },
|
|
54
|
+
{ name: 'to', type: 'address' },
|
|
55
|
+
{ name: 'value', type: 'uint256' },
|
|
56
|
+
{ name: 'validAfter', type: 'uint256' },
|
|
57
|
+
{ name: 'validBefore', type: 'uint256' },
|
|
58
|
+
{ name: 'nonce', type: 'bytes32' },
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
domain: {
|
|
62
|
+
name: 'USDC',
|
|
63
|
+
version: '2',
|
|
64
|
+
chainId: params.chainId,
|
|
65
|
+
verifyingContract: params.verifyingContract,
|
|
66
|
+
},
|
|
67
|
+
primaryType: 'TransferWithAuthorization',
|
|
68
|
+
message: {
|
|
69
|
+
from: params.from,
|
|
70
|
+
to: params.to,
|
|
71
|
+
value: params.value.toString(),
|
|
72
|
+
validAfter: params.validAfter.toString(),
|
|
73
|
+
validBefore: params.validBefore.toString(),
|
|
74
|
+
nonce: params.nonce,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Simplified payment request builder
|
|
80
|
+
* Returns all data needed to track and verify the payment
|
|
81
|
+
*/
|
|
82
|
+
export async function createPaymentRequest(handler, event, chainId, fromAddress, recipientAddress, paymentConfig, command) {
|
|
83
|
+
const usdcAddr = getUsdcAddress(chainId);
|
|
84
|
+
const nonce = generateNonce();
|
|
85
|
+
const { validAfter, validBefore } = getValidityWindow();
|
|
86
|
+
const value = parseUSDCPrice(paymentConfig.price);
|
|
87
|
+
const params = {
|
|
88
|
+
from: fromAddress,
|
|
89
|
+
to: recipientAddress,
|
|
90
|
+
value: value,
|
|
91
|
+
validAfter,
|
|
92
|
+
validBefore,
|
|
93
|
+
nonce,
|
|
94
|
+
chainId: chainId,
|
|
95
|
+
verifyingContract: usdcAddr,
|
|
96
|
+
};
|
|
97
|
+
const typedData = buildTransferAuthorizationTypedDataForSigning(params);
|
|
98
|
+
const signatureId = `payment-${Date.now()}-${nonce.slice(0, 10)}`;
|
|
99
|
+
// Format price for display
|
|
100
|
+
const priceDisplay = typeof paymentConfig.price === 'string' || typeof paymentConfig.price === 'number'
|
|
101
|
+
? String(paymentConfig.price)
|
|
102
|
+
: JSON.stringify(paymentConfig.price);
|
|
103
|
+
const result = await handler.sendInteractionRequest(event.channelId, {
|
|
104
|
+
case: 'signature',
|
|
105
|
+
value: {
|
|
106
|
+
id: signatureId,
|
|
107
|
+
type: InteractionRequestPayload_Signature_SignatureType.TYPED_DATA,
|
|
108
|
+
data: JSON.stringify(typedData),
|
|
109
|
+
chainId: params.chainId.toString(),
|
|
110
|
+
signerWallet: fromAddress,
|
|
111
|
+
title: `Payment Required for /${command} • ${priceDisplay} USDC`,
|
|
112
|
+
subtitle: `Sign to authorize payment`,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
signatureId,
|
|
117
|
+
params,
|
|
118
|
+
eventId: result.eventId,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Parses a USDC price to atomic units (6 decimals).
|
|
123
|
+
* Handles dollar signs, commas, and decimal amounts.
|
|
124
|
+
* Only string and number inputs are supported.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* parseUSDCPrice("$1.00") // 1000000n
|
|
128
|
+
* parseUSDCPrice(1.50) // 1500000n
|
|
129
|
+
* parseUSDCPrice("$1,000.00") // 1000000000n
|
|
130
|
+
*/
|
|
131
|
+
export function parseUSDCPrice(price) {
|
|
132
|
+
if (typeof price !== 'string' && typeof price !== 'number') {
|
|
133
|
+
throw new Error(`parseUSDCPrice only supports string or number inputs, got: ${typeof price}`);
|
|
134
|
+
}
|
|
135
|
+
const rawStr = String(price);
|
|
136
|
+
const sanitized = rawStr.replace(/[$,\s]/g, '').trim();
|
|
137
|
+
if (!/^\d+(\.\d{0,6})?$/.test(sanitized)) {
|
|
138
|
+
throw new Error(`Invalid USDC price format: ${JSON.stringify(price)}`);
|
|
139
|
+
}
|
|
140
|
+
const [whole, frac = ''] = sanitized.split('.');
|
|
141
|
+
const paddedFrac = frac.padEnd(6, '0').slice(0, 6);
|
|
142
|
+
return BigInt(whole || '0') * 1000000n + BigInt(paddedFrac);
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=payments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.js","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAG/C,OAAO,EAAE,iDAAiD,EAAE,MAAM,mBAAmB,CAAA;AAErF,MAAM,CAAC,MAAM,cAAc,GAA4B;IACnD,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,4CAA4C;IAC9D,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,4CAA4C;CAC1D,CAAA;AAkBD,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC5C,QAAQ,OAAO,EAAE,CAAC;QACd,KAAK,IAAI,CAAC,EAAE;YACR,OAAO,MAAM,CAAA;QACjB,KAAK,WAAW,CAAC,EAAE;YACf,OAAO,cAAc,CAAA;QACzB;YACI,MAAM,IAAI,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAA;IAC3D,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe;IAC1C,MAAM,OAAO,GAAG,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CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAElD,OAAO,MAAM,CAAC,KAAK,IAAI,GAAG,CAAC,GAAG,QAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;AACjE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"re-exports.d.ts","sourceRoot":"","sources":["../src/re-exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,+CAA+C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"re-exports.js","sourceRoot":"","sources":["../src/re-exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,+CAA+C,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Address, type Account, type Chain, type Client, type Transport } from 'viem';
|
|
2
|
+
import { Agent, type AgentCommand } from './agent';
|
|
3
|
+
/**
|
|
4
|
+
* The default slot for the implementation address for ERC-1967 Proxies
|
|
5
|
+
* keccak256('eip1967.proxy.implementation')) - 1
|
|
6
|
+
*/
|
|
7
|
+
export declare const PROXY_STORAGE_SLOT = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
|
|
8
|
+
/**
|
|
9
|
+
* Known modular account implementation addresses
|
|
10
|
+
*/
|
|
11
|
+
export declare const MODULAR_ACCOUNT_IMPLEMENTATIONS: {
|
|
12
|
+
/**
|
|
13
|
+
* Semi modular smart account bytecode for new accounts
|
|
14
|
+
* New accounts get this address as their implementation
|
|
15
|
+
*/
|
|
16
|
+
readonly NEW: "0x000000000000c5A9089039570Dd36455b5C07383";
|
|
17
|
+
/**
|
|
18
|
+
* Storage only smart account bytecode for existing accounts
|
|
19
|
+
* Upgraded accounts get this address as their implementation
|
|
20
|
+
* https://github.com/alchemyplatform/modular-account/blob/develop/src/account/SemiModularAccountStorageOnly.sol
|
|
21
|
+
*/
|
|
22
|
+
readonly UPGRADED: "0x0000000000006E2f9d80CaEc0Da6500f005EB25A";
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Check if an address has a deployed modular smart account implementation
|
|
26
|
+
* @param client - The public RPC viem client
|
|
27
|
+
* @param address - The address to check
|
|
28
|
+
* @returns True if the address has a deployed modular smart account implementation, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkSmartAccountImplementation(viem: Client<Transport, Chain, Account>, address: Address): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the deployed modular smart account for a userId (rootkey)
|
|
33
|
+
* This function:
|
|
34
|
+
* 1. Gets all linked wallets for the userId using the WalletLink contract
|
|
35
|
+
* 2. Checks each wallet to see if it has a deployed modular smart account
|
|
36
|
+
* 3. Returns the first modular smart account found, or null if none exist
|
|
37
|
+
*
|
|
38
|
+
* @param bot - The bot instance
|
|
39
|
+
* @param params - User id
|
|
40
|
+
* @returns The address of the deployed modular smart account, or null if none exists
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { getDeployedSmartAccount } from '@towns-labs/agent'
|
|
45
|
+
*
|
|
46
|
+
* // Simple usage with bot instance
|
|
47
|
+
* const address = await getDeployedSmartAccount(bot, userId)
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function getSmartAccountFromUserId(bot: Agent<AgentCommand[]>, params: {
|
|
51
|
+
userId: Address;
|
|
52
|
+
}): Promise<Address | null>;
|
|
53
|
+
export declare function getSmartAccountFromUserIdImpl(contractAddress: Address, viem: Client<Transport, Chain, Account>, userId: Address): Promise<Address | null>;
|
|
54
|
+
//# sourceMappingURL=smart-account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-account.d.ts","sourceRoot":"","sources":["../src/smart-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EAGP,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,SAAS,EACjB,MAAM,MAAM,CAAA;AAGb,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAElD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,uEACyC,CAAA;AAExE;;GAEG;AACH,eAAO,MAAM,+BAA+B;IACxC;;;OAGG;;IAEH;;;;OAIG;;CAEG,CAAA;AAUV;;;;;GAKG;AACH,wBAAsB,+BAA+B,CACjD,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,EACvC,OAAO,EAAE,OAAO,GACjB,OAAO,CAAC,OAAO,CAAC,CAyBlB;AAqCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,yBAAyB,CAC3C,GAAG,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC,EAC1B,MAAM,EAAE;IACJ,MAAM,EAAE,OAAO,CAAA;CAClB,GACF,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAGzB;AAED,wBAAsB,6BAA6B,CAC/C,eAAe,EAAE,OAAO,EACxB,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,EACvC,MAAM,EAAE,OAAO,GAChB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAezB"}
|