@actioncodes/protocol 1.0.0
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/LICENSE +201 -0
- package/README.md +55 -0
- package/dist/actioncode.d.ts +114 -0
- package/dist/actioncode.d.ts.map +1 -0
- package/dist/actioncode.js +159 -0
- package/dist/adapters/base.d.ts +52 -0
- package/dist/adapters/base.d.ts.map +1 -0
- package/dist/adapters/base.js +41 -0
- package/dist/adapters/solana/index.d.ts +2 -0
- package/dist/adapters/solana/index.d.ts.map +1 -0
- package/dist/adapters/solana/index.js +17 -0
- package/dist/adapters/solana/solana.d.ts +84 -0
- package/dist/adapters/solana/solana.d.ts.map +1 -0
- package/dist/adapters/solana/solana.js +223 -0
- package/dist/codegen.d.ts +73 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +118 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +11 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/meta.d.ts +54 -0
- package/dist/meta.d.ts.map +1 -0
- package/dist/meta.js +91 -0
- package/dist/protocol.d.ts +167 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +280 -0
- package/docs/README.md +59 -0
- package/docs/_media/LICENSE +201 -0
- package/docs/_media/README.md +28 -0
- package/docs/actioncode/README.md +21 -0
- package/docs/actioncode/classes/ActionCode.md +412 -0
- package/docs/actioncode/interfaces/ActionCodeFields.md +95 -0
- package/docs/actioncode/interfaces/ActionCodeMetadata.md +25 -0
- package/docs/actioncode/interfaces/ActionCodeTransaction.md +39 -0
- package/docs/actioncode/type-aliases/ActionCodeStatus.md +11 -0
- package/docs/adapters/base/README.md +11 -0
- package/docs/adapters/base/classes/BaseChainAdapter.md +222 -0
- package/docs/adapters/solana/README.md +19 -0
- package/docs/adapters/solana/solana/README.md +15 -0
- package/docs/adapters/solana/solana/classes/SolanaAdapter.md +306 -0
- package/docs/adapters/solana/solana/type-aliases/SolanaTransaction.md +13 -0
- package/docs/codegen/README.md +11 -0
- package/docs/codegen/classes/CodeGenerator.md +337 -0
- package/docs/constants/README.md +22 -0
- package/docs/constants/type-aliases/SupportedChain.md +11 -0
- package/docs/constants/variables/CODE_LENGTH.md +11 -0
- package/docs/constants/variables/CODE_TTL.md +11 -0
- package/docs/constants/variables/MAX_PREFIX_LENGTH.md +11 -0
- package/docs/constants/variables/MIN_PREFIX_LENGTH.md +11 -0
- package/docs/constants/variables/PROTOCOL_CODE_PREFIX.md +11 -0
- package/docs/constants/variables/PROTOCOL_PREFIX.md +11 -0
- package/docs/constants/variables/PROTOCOL_VERSION.md +11 -0
- package/docs/constants/variables/SUPPORTED_CHAINS.md +11 -0
- package/docs/index/README.md +139 -0
- package/docs/meta/README.md +15 -0
- package/docs/meta/classes/ProtocolMetaParser.md +177 -0
- package/docs/meta/interfaces/ProtocolMetaV1.md +59 -0
- package/docs/modules.md +17 -0
- package/docs/protocol/README.md +51 -0
- package/docs/protocol/classes/ActionCodesProtocol.md +616 -0
- package/docs/protocol/interfaces/ProtocolConfig.md +71 -0
- package/package.json +90 -0
package/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# 🛡️ Action Codes Protocol
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
**Action Codes Protocol** enables short-lived, cryptographically verifiable action codes that authorize blockchain transactions and intents without requiring live wallet sessions.
|
6
|
+
|
7
|
+
This repository contains the canonical specifications, SDK modules, and chain adapter interfaces that implement the Action Codes Protocol.
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
## ✨ Key Features
|
12
|
+
|
13
|
+
- 🔐 **Deterministic Code Generation**
|
14
|
+
Users can generate time-limited codes directly in their wallet or client, without external servers.
|
15
|
+
|
16
|
+
- ✅ **Signature-Based Verification**
|
17
|
+
Codes are signed by the wallet, and transactions must be signed by protocol-authorized relayers.
|
18
|
+
|
19
|
+
- 🧩 **Meta-Based Intent Encoding**
|
20
|
+
Each transaction carries an encoded `meta` string for verifiable context across chains.
|
21
|
+
|
22
|
+
- 🧱 **Chain-Agnostic Design**
|
23
|
+
Works on Solana today; built for future EVM, Cosmos, and more.
|
24
|
+
|
25
|
+
- 🌐 **Prefix Namespace System**
|
26
|
+
Enables ecosystem-wide namespacing (e.g. `JUP`, `ME`) for branded intents and UIs.
|
27
|
+
|
28
|
+
---
|
29
|
+
|
30
|
+
## 📦 Repository Structure
|
31
|
+
|
32
|
+
```
|
33
|
+
/src - SDK modules (codegen, meta, validator, blockchain adapters)
|
34
|
+
/specs - Formal specifications (AIPs)
|
35
|
+
README.md - You are here
|
36
|
+
LICENSE - Apache 2.0
|
37
|
+
```
|
38
|
+
|
39
|
+
---
|
40
|
+
|
41
|
+
## 📄 Specifications
|
42
|
+
|
43
|
+
[Protocol Specifications](./specs/README.md)
|
44
|
+
|
45
|
+
- [`AIP-0`](./specs/aip-0.md): Action Codes Protocol Architecture
|
46
|
+
- [`AIP-1`](./specs/aip-1.md): Protocol Meta Format
|
47
|
+
- [`AIP-2`](./specs/aip-2.md): Authority Signature Validation
|
48
|
+
- [`AIP-3`](./specs/aip-3.md): Intent Resolution & Routing
|
49
|
+
- [`AIP-4`](./specs/aip-4.md): Prefix System
|
50
|
+
|
51
|
+
---
|
52
|
+
|
53
|
+
## 📜 License
|
54
|
+
|
55
|
+
This protocol is open source under the [Apache 2.0 License](./LICENSE).
|
@@ -0,0 +1,114 @@
|
|
1
|
+
import { SUPPORTED_CHAINS } from "./constants";
|
2
|
+
export type ActionCodeStatus = 'pending' | 'resolved' | 'finalized' | 'expired' | 'error';
|
3
|
+
export interface ActionCodeMetadata {
|
4
|
+
description?: string;
|
5
|
+
params?: Record<string, any>;
|
6
|
+
}
|
7
|
+
export interface ActionCodeTransaction<T> {
|
8
|
+
transaction?: T;
|
9
|
+
txSignature?: string;
|
10
|
+
txType?: string;
|
11
|
+
}
|
12
|
+
export interface ActionCodeFields<T> {
|
13
|
+
code: string;
|
14
|
+
prefix: string;
|
15
|
+
pubkey: string;
|
16
|
+
timestamp: number;
|
17
|
+
signature: string;
|
18
|
+
chain: (typeof SUPPORTED_CHAINS)[number];
|
19
|
+
transaction?: ActionCodeTransaction<T>;
|
20
|
+
metadata?: ActionCodeMetadata;
|
21
|
+
expiresAt: number;
|
22
|
+
status: ActionCodeStatus;
|
23
|
+
}
|
24
|
+
export declare class ActionCode<T> {
|
25
|
+
private fields;
|
26
|
+
constructor(fields: ActionCodeFields<T>);
|
27
|
+
static fromPayload<T>(input: ActionCodeFields<T>): ActionCode<T>;
|
28
|
+
static fromEncoded<T>(encoded: string): ActionCode<T>;
|
29
|
+
get encoded(): string;
|
30
|
+
get isValid(): boolean;
|
31
|
+
get json(): ActionCodeFields<T>;
|
32
|
+
/**
|
33
|
+
* Get remaining time in milliseconds until expiration
|
34
|
+
* @returns Remaining time in milliseconds, or 0 if expired
|
35
|
+
*/
|
36
|
+
get remainingTime(): number;
|
37
|
+
/**
|
38
|
+
* Check if the action code has expired
|
39
|
+
* @returns True if the code has expired
|
40
|
+
*/
|
41
|
+
get expired(): boolean;
|
42
|
+
/**
|
43
|
+
* Get the target chain for this action code
|
44
|
+
* @returns Chain identifier (e.g., "solana", "evm")
|
45
|
+
*/
|
46
|
+
get chain(): string;
|
47
|
+
/**
|
48
|
+
* Get the current status of the action code
|
49
|
+
* @returns Current status
|
50
|
+
*/
|
51
|
+
get status(): ActionCodeStatus;
|
52
|
+
/**
|
53
|
+
* Get the action code string
|
54
|
+
* @returns The 8-character action code
|
55
|
+
*/
|
56
|
+
get code(): string;
|
57
|
+
/**
|
58
|
+
* Get the prefix used for this action code
|
59
|
+
* @returns Normalized prefix
|
60
|
+
*/
|
61
|
+
get prefix(): string;
|
62
|
+
/**
|
63
|
+
* Get the user's public key
|
64
|
+
* @returns User's public key
|
65
|
+
*/
|
66
|
+
get pubkey(): string;
|
67
|
+
/**
|
68
|
+
* Get the transaction data (chain-specific)
|
69
|
+
* @returns Transaction data or undefined
|
70
|
+
*/
|
71
|
+
get transaction(): ActionCodeTransaction<T> | undefined;
|
72
|
+
/**
|
73
|
+
* Get metadata associated with this action code
|
74
|
+
* @returns Metadata object or undefined
|
75
|
+
*/
|
76
|
+
get metadata(): ActionCodeFields<T>['metadata'] | undefined;
|
77
|
+
/**
|
78
|
+
* Get a human-readable description of the action
|
79
|
+
* @returns Description string or undefined
|
80
|
+
*/
|
81
|
+
get description(): string | undefined;
|
82
|
+
/**
|
83
|
+
* Get parameters associated with this action
|
84
|
+
* @returns Parameters object or undefined
|
85
|
+
*/
|
86
|
+
get params(): Record<string, any> | undefined;
|
87
|
+
/**
|
88
|
+
* Get the timestamp when the code was generated
|
89
|
+
* @returns Timestamp in milliseconds
|
90
|
+
*/
|
91
|
+
get timestamp(): number;
|
92
|
+
/**
|
93
|
+
* Get the user's signature
|
94
|
+
* @returns User's signature string
|
95
|
+
*/
|
96
|
+
get signature(): string;
|
97
|
+
/**
|
98
|
+
* Get a human-readable display string for the action code
|
99
|
+
* @returns Formatted display string
|
100
|
+
*/
|
101
|
+
get displayString(): string;
|
102
|
+
/**
|
103
|
+
* Get a formatted time string showing remaining time
|
104
|
+
* @returns Human-readable time string (e.g., "1m 30s remaining")
|
105
|
+
*/
|
106
|
+
get remainingTimeString(): string;
|
107
|
+
/**
|
108
|
+
* Get the code hash for this action code
|
109
|
+
* it is also used in the protocol meta as the code id
|
110
|
+
* @returns Code hash string
|
111
|
+
*/
|
112
|
+
get codeHash(): string;
|
113
|
+
}
|
114
|
+
//# sourceMappingURL=actioncode.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"actioncode.d.ts","sourceRoot":"","sources":["../src/actioncode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE1F,MAAM,WAAW,kBAAkB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,CAAC,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;IACzC,WAAW,CAAC,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,gBAAgB,CAAC;CAC5B;AAED,qBAAa,UAAU,CAAC,CAAC;IACT,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAE/C,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAOhE,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC;IAKrD,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,OAAO,IAAI,OAAO,CAQrB;IAED,IAAI,IAAI,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAE9B;IAID;;;OAGG;IACH,IAAI,aAAa,IAAI,MAAM,CAG1B;IAED;;;OAGG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,gBAAgB,CAE7B;IAED;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,IAAI,WAAW,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG,SAAS,CAEtD;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,SAAS,CAE1D;IAED;;;OAGG;IACH,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAE5C;IAED;;;OAGG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;;OAGG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;;OAGG;IACH,IAAI,aAAa,IAAI,MAAM,CAO1B;IAED;;;OAGG;IACH,IAAI,mBAAmB,IAAI,MAAM,CAchC;IAED;;;;OAIG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;CACJ"}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ActionCode = void 0;
|
4
|
+
const codegen_1 = require("./codegen");
|
5
|
+
class ActionCode {
|
6
|
+
constructor(fields) {
|
7
|
+
this.fields = fields;
|
8
|
+
}
|
9
|
+
static fromPayload(input) {
|
10
|
+
if (!input.code || !input.pubkey || !input.signature || !input.timestamp || !input.expiresAt || !input.chain || !input.status) {
|
11
|
+
throw new Error("Missing required fields in ActionCode payload");
|
12
|
+
}
|
13
|
+
return new ActionCode(input);
|
14
|
+
}
|
15
|
+
static fromEncoded(encoded) {
|
16
|
+
const decoded = JSON.parse(atob(encoded));
|
17
|
+
return ActionCode.fromPayload(decoded);
|
18
|
+
}
|
19
|
+
get encoded() {
|
20
|
+
return btoa(JSON.stringify(this.fields));
|
21
|
+
}
|
22
|
+
get isValid() {
|
23
|
+
return codegen_1.CodeGenerator.validateCode(this.fields.code, this.fields.pubkey, this.fields.timestamp, this.fields.signature, this.fields.prefix);
|
24
|
+
}
|
25
|
+
get json() {
|
26
|
+
return this.fields;
|
27
|
+
}
|
28
|
+
// UX-focused helper methods
|
29
|
+
/**
|
30
|
+
* Get remaining time in milliseconds until expiration
|
31
|
+
* @returns Remaining time in milliseconds, or 0 if expired
|
32
|
+
*/
|
33
|
+
get remainingTime() {
|
34
|
+
const now = Date.now();
|
35
|
+
return Math.max(0, this.fields.expiresAt - now); // TODO: rename to remainingTime
|
36
|
+
}
|
37
|
+
/**
|
38
|
+
* Check if the action code has expired
|
39
|
+
* @returns True if the code has expired
|
40
|
+
*/
|
41
|
+
get expired() {
|
42
|
+
return this.remainingTime === 0; // TODO: rename to expired
|
43
|
+
}
|
44
|
+
/**
|
45
|
+
* Get the target chain for this action code
|
46
|
+
* @returns Chain identifier (e.g., "solana", "evm")
|
47
|
+
*/
|
48
|
+
get chain() {
|
49
|
+
return this.fields.chain;
|
50
|
+
}
|
51
|
+
/**
|
52
|
+
* Get the current status of the action code
|
53
|
+
* @returns Current status
|
54
|
+
*/
|
55
|
+
get status() {
|
56
|
+
return this.fields.status;
|
57
|
+
}
|
58
|
+
/**
|
59
|
+
* Get the action code string
|
60
|
+
* @returns The 8-character action code
|
61
|
+
*/
|
62
|
+
get code() {
|
63
|
+
return this.fields.code;
|
64
|
+
}
|
65
|
+
/**
|
66
|
+
* Get the prefix used for this action code
|
67
|
+
* @returns Normalized prefix
|
68
|
+
*/
|
69
|
+
get prefix() {
|
70
|
+
return this.fields.prefix;
|
71
|
+
}
|
72
|
+
/**
|
73
|
+
* Get the user's public key
|
74
|
+
* @returns User's public key
|
75
|
+
*/
|
76
|
+
get pubkey() {
|
77
|
+
return this.fields.pubkey;
|
78
|
+
}
|
79
|
+
/**
|
80
|
+
* Get the transaction data (chain-specific)
|
81
|
+
* @returns Transaction data or undefined
|
82
|
+
*/
|
83
|
+
get transaction() {
|
84
|
+
return this.fields.transaction;
|
85
|
+
}
|
86
|
+
/**
|
87
|
+
* Get metadata associated with this action code
|
88
|
+
* @returns Metadata object or undefined
|
89
|
+
*/
|
90
|
+
get metadata() {
|
91
|
+
return this.fields.metadata;
|
92
|
+
}
|
93
|
+
/**
|
94
|
+
* Get a human-readable description of the action
|
95
|
+
* @returns Description string or undefined
|
96
|
+
*/
|
97
|
+
get description() {
|
98
|
+
return this.fields.metadata?.description;
|
99
|
+
}
|
100
|
+
/**
|
101
|
+
* Get parameters associated with this action
|
102
|
+
* @returns Parameters object or undefined
|
103
|
+
*/
|
104
|
+
get params() {
|
105
|
+
return this.fields.metadata?.params;
|
106
|
+
}
|
107
|
+
/**
|
108
|
+
* Get the timestamp when the code was generated
|
109
|
+
* @returns Timestamp in milliseconds
|
110
|
+
*/
|
111
|
+
get timestamp() {
|
112
|
+
return this.fields.timestamp;
|
113
|
+
}
|
114
|
+
/**
|
115
|
+
* Get the user's signature
|
116
|
+
* @returns User's signature string
|
117
|
+
*/
|
118
|
+
get signature() {
|
119
|
+
return this.fields.signature;
|
120
|
+
}
|
121
|
+
/**
|
122
|
+
* Get a human-readable display string for the action code
|
123
|
+
* @returns Formatted display string
|
124
|
+
*/
|
125
|
+
get displayString() {
|
126
|
+
const prefix = this.fields.prefix === 'DEFAULT' ? '' : `${this.fields.prefix}-`;
|
127
|
+
const code = this.fields.code;
|
128
|
+
const chain = this.fields.chain;
|
129
|
+
const status = this.fields.status;
|
130
|
+
return `${prefix}${code} (${chain}, ${status})`;
|
131
|
+
}
|
132
|
+
/**
|
133
|
+
* Get a formatted time string showing remaining time
|
134
|
+
* @returns Human-readable time string (e.g., "1m 30s remaining")
|
135
|
+
*/
|
136
|
+
get remainingTimeString() {
|
137
|
+
const remaining = this.remainingTime;
|
138
|
+
if (remaining === 0) {
|
139
|
+
return 'Expired';
|
140
|
+
}
|
141
|
+
const minutes = Math.floor(remaining / 60000);
|
142
|
+
const seconds = Math.floor((remaining % 60000) / 1000);
|
143
|
+
if (minutes > 0) {
|
144
|
+
return `${minutes}m ${seconds}s remaining`;
|
145
|
+
}
|
146
|
+
else {
|
147
|
+
return `${seconds}s remaining`;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
/**
|
151
|
+
* Get the code hash for this action code
|
152
|
+
* it is also used in the protocol meta as the code id
|
153
|
+
* @returns Code hash string
|
154
|
+
*/
|
155
|
+
get codeHash() {
|
156
|
+
return codegen_1.CodeGenerator.deriveCodeHash(this.fields.pubkey, this.fields.prefix, this.fields.timestamp);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
exports.ActionCode = ActionCode;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { ProtocolMetaV1 } from '../meta';
|
2
|
+
/**
|
3
|
+
* Base adapter class for chain-specific protocol meta operations
|
4
|
+
* @template T - Chain-specific transaction type
|
5
|
+
*/
|
6
|
+
export declare abstract class BaseChainAdapter<T = any> {
|
7
|
+
abstract readonly chain: string;
|
8
|
+
/**
|
9
|
+
* Encode protocol meta for this chain
|
10
|
+
* @param meta - ProtocolMetaV1 object
|
11
|
+
* @returns Chain-specific encoded data
|
12
|
+
*/
|
13
|
+
abstract encode(meta: ProtocolMetaV1): any;
|
14
|
+
/**
|
15
|
+
* Decode protocol meta from chain-specific transaction
|
16
|
+
* @param tx - Chain-specific transaction
|
17
|
+
* @returns Decoded ProtocolMetaV1 or null
|
18
|
+
*/
|
19
|
+
abstract decode(tx: T): ProtocolMetaV1 | null;
|
20
|
+
/**
|
21
|
+
* Validate transaction with protocol meta and authority list
|
22
|
+
* @param tx - Chain-specific transaction
|
23
|
+
* @param authorities - Array of valid protocol authority identifiers
|
24
|
+
* @param expectedPrefix - Expected protocol prefix (default: 'DEFAULT')
|
25
|
+
* @returns True if transaction is valid
|
26
|
+
*/
|
27
|
+
abstract validate(tx: T, authorities: string[], expectedPrefix?: string): boolean;
|
28
|
+
/**
|
29
|
+
* Check if the issuer has signed the transaction
|
30
|
+
* @param tx - Chain-specific transaction
|
31
|
+
* @param issuer - Issuer public key to check
|
32
|
+
* @returns True if issuer has signed
|
33
|
+
*/
|
34
|
+
abstract hasIssuerSignature(tx: T, issuer: string): boolean;
|
35
|
+
/**
|
36
|
+
* Detect tampered transactions by cross-checking metadata
|
37
|
+
* @param tx - Chain-specific transaction
|
38
|
+
* @param authorities - Array of valid protocol authority identifiers
|
39
|
+
* @param expectedPrefix - Expected protocol prefix
|
40
|
+
* @returns True if transaction is valid and not tampered
|
41
|
+
*/
|
42
|
+
detectTampering(tx: T, authorities: string[], expectedPrefix?: string): boolean;
|
43
|
+
/**
|
44
|
+
* Chain-specific transaction integrity validation
|
45
|
+
* Override this method for additional validation logic
|
46
|
+
* @param tx - Chain-specific transaction
|
47
|
+
* @param meta - Decoded protocol meta
|
48
|
+
* @returns True if transaction integrity is valid
|
49
|
+
*/
|
50
|
+
protected abstract validateTransactionIntegrity(tx: T, meta: ProtocolMetaV1): boolean;
|
51
|
+
}
|
52
|
+
//# sourceMappingURL=base.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/adapters/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC;;;GAGG;AACH,8BAAsB,gBAAgB,CAAC,CAAC,GAAG,GAAG;IAC1C,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEhC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,GAAG,GAAG;IAE1C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,GAAG,cAAc,GAAG,IAAI;IAE7C;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO;IAEjF;;;;;OAKG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAE3D;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,cAAc,GAAE,MAAkB,GAAG,OAAO;IA8B1F;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO;CACxF"}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BaseChainAdapter = void 0;
|
4
|
+
/**
|
5
|
+
* Base adapter class for chain-specific protocol meta operations
|
6
|
+
* @template T - Chain-specific transaction type
|
7
|
+
*/
|
8
|
+
class BaseChainAdapter {
|
9
|
+
/**
|
10
|
+
* Detect tampered transactions by cross-checking metadata
|
11
|
+
* @param tx - Chain-specific transaction
|
12
|
+
* @param authorities - Array of valid protocol authority identifiers
|
13
|
+
* @param expectedPrefix - Expected protocol prefix
|
14
|
+
* @returns True if transaction is valid and not tampered
|
15
|
+
*/
|
16
|
+
detectTampering(tx, authorities, expectedPrefix = 'DEFAULT') {
|
17
|
+
// First, decode the protocol meta from the transaction
|
18
|
+
const meta = this.decode(tx);
|
19
|
+
if (!meta) {
|
20
|
+
return false; // No protocol meta found
|
21
|
+
}
|
22
|
+
// Validate the meta structure
|
23
|
+
if (meta.version !== '1') {
|
24
|
+
return false; // Invalid version
|
25
|
+
}
|
26
|
+
if (meta.prefix !== expectedPrefix) {
|
27
|
+
return false; // Wrong prefix
|
28
|
+
}
|
29
|
+
// Check if issuer is in the authorities list
|
30
|
+
if (!meta.iss || !authorities.includes(meta.iss)) {
|
31
|
+
return false; // Invalid issuer
|
32
|
+
}
|
33
|
+
// Verify the issuer has actually signed the transaction
|
34
|
+
if (!this.hasIssuerSignature(tx, meta.iss)) {
|
35
|
+
return false; // Issuer didn't sign
|
36
|
+
}
|
37
|
+
// Additional chain-specific validation
|
38
|
+
return this.validateTransactionIntegrity(tx, meta);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
exports.BaseChainAdapter = BaseChainAdapter;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/solana/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./solana"), exports);
|