@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.
Files changed (65) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +55 -0
  3. package/dist/actioncode.d.ts +114 -0
  4. package/dist/actioncode.d.ts.map +1 -0
  5. package/dist/actioncode.js +159 -0
  6. package/dist/adapters/base.d.ts +52 -0
  7. package/dist/adapters/base.d.ts.map +1 -0
  8. package/dist/adapters/base.js +41 -0
  9. package/dist/adapters/solana/index.d.ts +2 -0
  10. package/dist/adapters/solana/index.d.ts.map +1 -0
  11. package/dist/adapters/solana/index.js +17 -0
  12. package/dist/adapters/solana/solana.d.ts +84 -0
  13. package/dist/adapters/solana/solana.d.ts.map +1 -0
  14. package/dist/adapters/solana/solana.js +223 -0
  15. package/dist/codegen.d.ts +73 -0
  16. package/dist/codegen.d.ts.map +1 -0
  17. package/dist/codegen.js +118 -0
  18. package/dist/constants.d.ts +10 -0
  19. package/dist/constants.d.ts.map +1 -0
  20. package/dist/constants.js +11 -0
  21. package/dist/index.d.ts +9 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +23 -0
  24. package/dist/meta.d.ts +54 -0
  25. package/dist/meta.d.ts.map +1 -0
  26. package/dist/meta.js +91 -0
  27. package/dist/protocol.d.ts +167 -0
  28. package/dist/protocol.d.ts.map +1 -0
  29. package/dist/protocol.js +280 -0
  30. package/docs/README.md +59 -0
  31. package/docs/_media/LICENSE +201 -0
  32. package/docs/_media/README.md +28 -0
  33. package/docs/actioncode/README.md +21 -0
  34. package/docs/actioncode/classes/ActionCode.md +412 -0
  35. package/docs/actioncode/interfaces/ActionCodeFields.md +95 -0
  36. package/docs/actioncode/interfaces/ActionCodeMetadata.md +25 -0
  37. package/docs/actioncode/interfaces/ActionCodeTransaction.md +39 -0
  38. package/docs/actioncode/type-aliases/ActionCodeStatus.md +11 -0
  39. package/docs/adapters/base/README.md +11 -0
  40. package/docs/adapters/base/classes/BaseChainAdapter.md +222 -0
  41. package/docs/adapters/solana/README.md +19 -0
  42. package/docs/adapters/solana/solana/README.md +15 -0
  43. package/docs/adapters/solana/solana/classes/SolanaAdapter.md +306 -0
  44. package/docs/adapters/solana/solana/type-aliases/SolanaTransaction.md +13 -0
  45. package/docs/codegen/README.md +11 -0
  46. package/docs/codegen/classes/CodeGenerator.md +337 -0
  47. package/docs/constants/README.md +22 -0
  48. package/docs/constants/type-aliases/SupportedChain.md +11 -0
  49. package/docs/constants/variables/CODE_LENGTH.md +11 -0
  50. package/docs/constants/variables/CODE_TTL.md +11 -0
  51. package/docs/constants/variables/MAX_PREFIX_LENGTH.md +11 -0
  52. package/docs/constants/variables/MIN_PREFIX_LENGTH.md +11 -0
  53. package/docs/constants/variables/PROTOCOL_CODE_PREFIX.md +11 -0
  54. package/docs/constants/variables/PROTOCOL_PREFIX.md +11 -0
  55. package/docs/constants/variables/PROTOCOL_VERSION.md +11 -0
  56. package/docs/constants/variables/SUPPORTED_CHAINS.md +11 -0
  57. package/docs/index/README.md +139 -0
  58. package/docs/meta/README.md +15 -0
  59. package/docs/meta/classes/ProtocolMetaParser.md +177 -0
  60. package/docs/meta/interfaces/ProtocolMetaV1.md +59 -0
  61. package/docs/modules.md +17 -0
  62. package/docs/protocol/README.md +51 -0
  63. package/docs/protocol/classes/ActionCodesProtocol.md +616 -0
  64. package/docs/protocol/interfaces/ProtocolConfig.md +71 -0
  65. package/package.json +90 -0
package/dist/meta.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProtocolMetaParser = void 0;
4
+ const codegen_1 = require("./codegen");
5
+ const constants_1 = require("./constants");
6
+ /**
7
+ * Protocol meta parser for structured memo/message parsing
8
+ */
9
+ class ProtocolMetaParser {
10
+ /**
11
+ * Parse protocol meta from string
12
+ * @param metaString - The protocol meta string to parse
13
+ * @returns Parsed ProtocolMeta object or null if invalid
14
+ */
15
+ static parse(metaString) {
16
+ const match = metaString.match(this.PROTOCOL_REGEX);
17
+ if (!match) {
18
+ return null;
19
+ }
20
+ const [, protocolPrefix, version, prefix, initiator, id, iss, params] = match;
21
+ // Validate protocol prefix
22
+ if (protocolPrefix !== constants_1.PROTOCOL_PREFIX) {
23
+ return null;
24
+ }
25
+ return {
26
+ version,
27
+ prefix,
28
+ initiator,
29
+ id,
30
+ iss,
31
+ params: params || undefined
32
+ };
33
+ }
34
+ /**
35
+ * Serialize ProtocolMeta to string
36
+ * @param meta - The protocol meta to serialize
37
+ * @returns Serialized protocol meta string
38
+ */
39
+ static serialize(meta) {
40
+ let result = `${constants_1.PROTOCOL_PREFIX}:v=${meta.version}&pre=${meta.prefix}&ini=${meta.initiator}&id=${meta.id}&iss=${meta.iss}`;
41
+ if (meta.params) {
42
+ result += `&p=${meta.params}`;
43
+ }
44
+ return result;
45
+ }
46
+ /**
47
+ * Create protocol meta from code and parameters
48
+ * @param initiator - The initiator public key
49
+ * @param iss - The issuer (protocol authority)
50
+ * @param prefix - The prefix (default: "DEFAULT")
51
+ * @param params - Optional parameters
52
+ * @param timestamp - Optional timestamp
53
+ * @returns ProtocolMeta object
54
+ */
55
+ static fromInitiator(initiator, iss, prefix = "DEFAULT", params, timestamp) {
56
+ const codeHash = codegen_1.CodeGenerator.deriveCodeHash(initiator, prefix, timestamp);
57
+ return {
58
+ version: constants_1.PROTOCOL_VERSION,
59
+ prefix,
60
+ initiator,
61
+ id: codeHash,
62
+ iss,
63
+ params
64
+ };
65
+ }
66
+ /**
67
+ * Validate if a code matches the protocol meta
68
+ * @param meta - The protocol meta to validate against
69
+ * @param timestamp - Optional timestamp for validation (if not provided, uses current time)
70
+ * @returns True if the meta is valid
71
+ */
72
+ static validateCode(meta, timestamp) {
73
+ const expectedHash = codegen_1.CodeGenerator.deriveCodeHash(meta.initiator, meta.prefix, timestamp);
74
+ return meta.id === expectedHash;
75
+ }
76
+ /**
77
+ * Validate if a code matches the protocol meta by parsing from string
78
+ * @param metaString - The protocol meta string to validate against
79
+ * @param timestamp - Optional timestamp for validation (if not provided, uses current time)
80
+ * @returns True if the code matches the meta
81
+ */
82
+ static validateMetaFromString(metaString, timestamp) {
83
+ const meta = this.parse(metaString);
84
+ if (!meta) {
85
+ return false;
86
+ }
87
+ return this.validateCode(meta, timestamp);
88
+ }
89
+ }
90
+ exports.ProtocolMetaParser = ProtocolMetaParser;
91
+ ProtocolMetaParser.PROTOCOL_REGEX = /^([^:]+):v=(\d+)&pre=([^&]*)&ini=([^&]*)&id=([^&]*)&iss=([^&]+)(?:&p=([^&]+))?$/;
@@ -0,0 +1,167 @@
1
+ import { ProtocolMetaV1 } from './meta';
2
+ import { ActionCode } from './actioncode';
3
+ import { BaseChainAdapter } from './adapters/base';
4
+ import { SupportedChain } from './constants';
5
+ /**
6
+ * OTA Protocol Configuration
7
+ */
8
+ export interface ProtocolConfig {
9
+ /** Protocol version */
10
+ version: string;
11
+ /** Default prefix for action codes */
12
+ defaultPrefix: string;
13
+ /** Code TTL in milliseconds */
14
+ codeTTL: number;
15
+ /** Code length in digits */
16
+ codeLength: number;
17
+ /** Maximum prefix length */
18
+ maxPrefixLength: number;
19
+ /** Minimum prefix length */
20
+ minPrefixLength: number;
21
+ }
22
+ /**
23
+ * OTA Protocol - Main entry point for the One-Time Action Code Protocol
24
+ *
25
+ * Provides a unified interface for generating, validating, and managing
26
+ * action codes across multiple blockchain networks.
27
+ */
28
+ export declare class ActionCodesProtocol {
29
+ private config;
30
+ private adapters;
31
+ constructor(config?: Partial<ProtocolConfig>);
32
+ /**
33
+ * Register a chain adapter
34
+ * @param adapter - Chain adapter implementation
35
+ */
36
+ registerAdapter<T>(adapter: BaseChainAdapter<T>): void;
37
+ /**
38
+ * Get registered chain adapters
39
+ * @returns Array of registered chain identifiers
40
+ */
41
+ getRegisteredChains(): string[];
42
+ /**
43
+ * Check if a chain is supported
44
+ * @param chain - Chain identifier
45
+ * @returns True if chain is supported
46
+ */
47
+ isChainSupported(chain: string): boolean;
48
+ /**
49
+ * Get chain adapter with proper typing
50
+ * @param chain - Chain identifier
51
+ * @returns Chain adapter or undefined
52
+ */
53
+ getChainAdapter<T = any>(chain: string): BaseChainAdapter<T> | undefined;
54
+ /**
55
+ * Generate an action code for a specific chain
56
+ * @param pubkey - User's public key
57
+ * @param signature - User's signature
58
+ * @param chain - Target chain
59
+ * @param prefix - Optional prefix (defaults to config defaultPrefix)
60
+ * @param timestamp - Optional timestamp (defaults to now)
61
+ * @returns ActionCode object
62
+ */
63
+ generateActionCode(pubkey: string, signature: string, chain: SupportedChain, prefix?: string, timestamp?: number): ActionCode<string>;
64
+ /**
65
+ * Validate an action code
66
+ * @param actionCode - ActionCode to validate
67
+ * @returns True if valid
68
+ */
69
+ validateActionCode(actionCode: ActionCode<string>): boolean;
70
+ /**
71
+ * Attach a transaction to an action code
72
+ * @param actionCode - ActionCode to attach transaction to
73
+ * @param transaction - Chain-specific transaction data
74
+ * @param txType - Optional transaction type
75
+ * @returns Updated ActionCode
76
+ */
77
+ attachTransaction(actionCode: ActionCode<string>, transaction: string, txType?: string): ActionCode<string>;
78
+ /**
79
+ * Finalize an action code with transaction signature
80
+ * @param actionCode - ActionCode to finalize
81
+ * @param txSignature - Transaction signature
82
+ * @returns Updated ActionCode
83
+ */
84
+ finalizeActionCode(actionCode: ActionCode<string>, txSignature: string): ActionCode<string>;
85
+ /**
86
+ * Create protocol meta for a transaction
87
+ * @param actionCode - ActionCode to create meta for
88
+ * @param issuer - Optional issuer public key
89
+ * @param params - Optional parameters
90
+ * @returns ProtocolMetaV1 object
91
+ */
92
+ createProtocolMeta(actionCode: ActionCode<string>, issuer?: string, params?: string): ProtocolMetaV1;
93
+ /**
94
+ * Encode protocol meta for a specific chain
95
+ * @param meta - ProtocolMetaV1 object
96
+ * @param chain - Target chain
97
+ * @returns Chain-specific encoded meta
98
+ */
99
+ encodeProtocolMeta(meta: ProtocolMetaV1, chain: string): any;
100
+ /**
101
+ * Decode protocol meta from a transaction
102
+ * @param transaction - Chain-specific transaction
103
+ * @param chain - Source chain
104
+ * @returns Decoded ProtocolMetaV1 or null
105
+ */
106
+ decodeProtocolMeta(transaction: any, chain: string): ProtocolMetaV1 | null;
107
+ /**
108
+ * Validate a transaction with protocol meta
109
+ * @param transaction - Chain-specific transaction
110
+ * @param chain - Source chain
111
+ * @param authorities - Array of valid protocol authority identifiers
112
+ * @param expectedPrefix - Expected protocol prefix
113
+ * @returns True if transaction is valid
114
+ */
115
+ validateTransaction(transaction: any, chain: string, authorities: string[], expectedPrefix?: string): boolean;
116
+ /**
117
+ * Type-safe transaction validation for specific chains
118
+ * @param transaction - Chain-specific transaction
119
+ * @param chain - Source chain
120
+ * @param authorities - Array of valid protocol authority identifiers
121
+ * @param expectedPrefix - Expected protocol prefix
122
+ * @returns True if transaction is valid
123
+ */
124
+ validateTransactionTyped<T>(transaction: T, chain: string, authorities: string[], expectedPrefix?: string): boolean;
125
+ /**
126
+ * Detect tampered transactions with type safety
127
+ * @param transaction - Chain-specific transaction
128
+ * @param chain - Source chain
129
+ * @param authorities - Array of valid protocol authority identifiers
130
+ * @param expectedPrefix - Expected protocol prefix
131
+ * @returns True if transaction is valid and not tampered
132
+ */
133
+ detectTampering<T>(transaction: T, chain: string, authorities: string[], expectedPrefix?: string): boolean;
134
+ /**
135
+ * Decode protocol meta with type safety
136
+ * @param transaction - Chain-specific transaction
137
+ * @param chain - Source chain
138
+ * @returns Decoded ProtocolMetaV1 or null
139
+ */
140
+ decodeProtocolMetaTyped<T>(transaction: T, chain: string): ProtocolMetaV1 | null;
141
+ /**
142
+ * Get protocol configuration
143
+ * @returns Current protocol configuration
144
+ */
145
+ getConfig(): ProtocolConfig;
146
+ /**
147
+ * Update protocol configuration
148
+ * @param updates - Configuration updates
149
+ */
150
+ updateConfig(updates: Partial<ProtocolConfig>): void;
151
+ /**
152
+ * Create a new protocol instance with default configuration
153
+ * @returns New protocol instance
154
+ */
155
+ static create(): ActionCodesProtocol;
156
+ /**
157
+ * Create a new protocol instance with custom configuration
158
+ * @param config - Custom configuration
159
+ * @returns New protocol instance
160
+ */
161
+ static createWithConfig(config: Partial<ProtocolConfig>): ActionCodesProtocol;
162
+ }
163
+ export type { ActionCode, ActionCodeStatus, ActionCodeTransaction } from './actioncode';
164
+ export type { ProtocolMetaV1 } from './meta';
165
+ export { SUPPORTED_CHAINS } from './constants';
166
+ export type { SupportedChain } from './constants';
167
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,UAAU,EAA2C,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAA8D,cAAc,EAA2C,MAAM,aAAa,CAAC;AAElJ;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,4BAA4B;IAC5B,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;GAKG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,QAAQ,CAAiD;gBAErD,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAY5C;;;OAGG;IACH,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI;IAItD;;;OAGG;IACH,mBAAmB,IAAI,MAAM,EAAE;IAI/B;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIxC;;;;OAIG;IACH,eAAe,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,SAAS;IAIxE;;;;;;;;OAQG;IACH,kBAAkB,CACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,cAAc,EACrB,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACnB,UAAU,CAAC,MAAM,CAAC;IA+BrB;;;;OAIG;IACH,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,OAAO;IAgB3D;;;;;;OAMG;IACH,iBAAiB,CACb,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,EAC9B,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GAChB,UAAU,CAAC,MAAM,CAAC;IAuBrB;;;;;OAKG;IACH,kBAAkB,CACd,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,EAC9B,WAAW,EAAE,MAAM,GACpB,UAAU,CAAC,MAAM,CAAC;IAsBrB;;;;;;OAMG;IACH,kBAAkB,CACd,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,EAC9B,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,GAChB,cAAc;IASjB;;;;;OAKG;IACH,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG;IAS5D;;;;;OAKG;IACH,kBAAkB,CAAC,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAS1E;;;;;;;OAOG;IACH,mBAAmB,CACf,WAAW,EAAE,GAAG,EAChB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EAAE,EACrB,cAAc,CAAC,EAAE,MAAM,GACxB,OAAO;IASV;;;;;;;OAOG;IACH,wBAAwB,CAAC,CAAC,EACtB,WAAW,EAAE,CAAC,EACd,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EAAE,EACrB,cAAc,CAAC,EAAE,MAAM,GACxB,OAAO;IASV;;;;;;;OAOG;IACH,eAAe,CAAC,CAAC,EACb,WAAW,EAAE,CAAC,EACd,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EAAE,EACrB,cAAc,CAAC,EAAE,MAAM,GACxB,OAAO;IASV;;;;;OAKG;IACH,uBAAuB,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAShF;;;OAGG;IACH,SAAS,IAAI,cAAc;IAI3B;;;OAGG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;IAIpD;;;OAGG;IACH,MAAM,CAAC,MAAM,IAAI,mBAAmB;IAIpC;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,mBAAmB;CAGhF;AAGD,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACxF,YAAY,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAG7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUPPORTED_CHAINS = exports.ActionCodesProtocol = void 0;
4
+ const codegen_1 = require("./codegen");
5
+ const meta_1 = require("./meta");
6
+ const actioncode_1 = require("./actioncode");
7
+ const constants_1 = require("./constants");
8
+ /**
9
+ * OTA Protocol - Main entry point for the One-Time Action Code Protocol
10
+ *
11
+ * Provides a unified interface for generating, validating, and managing
12
+ * action codes across multiple blockchain networks.
13
+ */
14
+ class ActionCodesProtocol {
15
+ constructor(config) {
16
+ this.adapters = new Map();
17
+ this.config = {
18
+ version: constants_1.PROTOCOL_VERSION,
19
+ defaultPrefix: constants_1.PROTOCOL_CODE_PREFIX,
20
+ codeTTL: constants_1.CODE_TTL,
21
+ codeLength: constants_1.CODE_LENGTH,
22
+ maxPrefixLength: constants_1.MAX_PREFIX_LENGTH,
23
+ minPrefixLength: constants_1.MIN_PREFIX_LENGTH,
24
+ ...config
25
+ };
26
+ }
27
+ /**
28
+ * Register a chain adapter
29
+ * @param adapter - Chain adapter implementation
30
+ */
31
+ registerAdapter(adapter) {
32
+ this.adapters.set(adapter.chain, adapter);
33
+ }
34
+ /**
35
+ * Get registered chain adapters
36
+ * @returns Array of registered chain identifiers
37
+ */
38
+ getRegisteredChains() {
39
+ return Array.from(this.adapters.keys());
40
+ }
41
+ /**
42
+ * Check if a chain is supported
43
+ * @param chain - Chain identifier
44
+ * @returns True if chain is supported
45
+ */
46
+ isChainSupported(chain) {
47
+ return this.adapters.has(chain);
48
+ }
49
+ /**
50
+ * Get chain adapter with proper typing
51
+ * @param chain - Chain identifier
52
+ * @returns Chain adapter or undefined
53
+ */
54
+ getChainAdapter(chain) {
55
+ return this.adapters.get(chain);
56
+ }
57
+ /**
58
+ * Generate an action code for a specific chain
59
+ * @param pubkey - User's public key
60
+ * @param signature - User's signature
61
+ * @param chain - Target chain
62
+ * @param prefix - Optional prefix (defaults to config defaultPrefix)
63
+ * @param timestamp - Optional timestamp (defaults to now)
64
+ * @returns ActionCode object
65
+ */
66
+ generateActionCode(pubkey, signature, chain, prefix, timestamp) {
67
+ if (!this.isChainSupported(chain)) {
68
+ throw new Error(`Chain '${chain}' is not supported. Registered chains: ${this.getRegisteredChains().join(', ')}`);
69
+ }
70
+ const normalizedPrefix = prefix || this.config.defaultPrefix;
71
+ const ts = timestamp || Date.now();
72
+ // Generate code using CodeGenerator
73
+ const { code, issuedAt, expiresAt } = codegen_1.CodeGenerator.generateCode(pubkey, signature, normalizedPrefix, ts);
74
+ // Create ActionCode object
75
+ const actionCodeFields = {
76
+ code,
77
+ prefix: normalizedPrefix,
78
+ pubkey,
79
+ timestamp: issuedAt,
80
+ signature,
81
+ chain,
82
+ expiresAt,
83
+ status: 'pending'
84
+ };
85
+ return actioncode_1.ActionCode.fromPayload(actionCodeFields);
86
+ }
87
+ /**
88
+ * Validate an action code
89
+ * @param actionCode - ActionCode to validate
90
+ * @returns True if valid
91
+ */
92
+ validateActionCode(actionCode) {
93
+ const chain = actionCode.chain;
94
+ if (!this.isChainSupported(chain)) {
95
+ return false;
96
+ }
97
+ // Basic validation - check if expired
98
+ if (actionCode.expired) {
99
+ return false;
100
+ }
101
+ // Chain-specific validation would be done when attaching transactions
102
+ return true;
103
+ }
104
+ /**
105
+ * Attach a transaction to an action code
106
+ * @param actionCode - ActionCode to attach transaction to
107
+ * @param transaction - Chain-specific transaction data
108
+ * @param txType - Optional transaction type
109
+ * @returns Updated ActionCode
110
+ */
111
+ attachTransaction(actionCode, transaction, txType) {
112
+ const chain = actionCode.chain;
113
+ if (!this.isChainSupported(chain)) {
114
+ throw new Error(`Chain '${chain}' is not supported`);
115
+ }
116
+ // Create transaction object
117
+ const txObject = {
118
+ transaction,
119
+ txType: txType || chain
120
+ };
121
+ // Update ActionCode
122
+ const updatedFields = {
123
+ ...actionCode.json,
124
+ transaction: txObject,
125
+ status: 'resolved'
126
+ };
127
+ return actioncode_1.ActionCode.fromPayload(updatedFields);
128
+ }
129
+ /**
130
+ * Finalize an action code with transaction signature
131
+ * @param actionCode - ActionCode to finalize
132
+ * @param txSignature - Transaction signature
133
+ * @returns Updated ActionCode
134
+ */
135
+ finalizeActionCode(actionCode, txSignature) {
136
+ const currentTransaction = actionCode.transaction;
137
+ if (!currentTransaction) {
138
+ throw new Error('Cannot finalize ActionCode without attached transaction');
139
+ }
140
+ // Update transaction with signature
141
+ const updatedTransaction = {
142
+ ...currentTransaction,
143
+ txSignature
144
+ };
145
+ // Update ActionCode
146
+ const updatedFields = {
147
+ ...actionCode.json,
148
+ transaction: updatedTransaction,
149
+ status: 'finalized'
150
+ };
151
+ return actioncode_1.ActionCode.fromPayload(updatedFields);
152
+ }
153
+ /**
154
+ * Create protocol meta for a transaction
155
+ * @param actionCode - ActionCode to create meta for
156
+ * @param issuer - Optional issuer public key
157
+ * @param params - Optional parameters
158
+ * @returns ProtocolMetaV1 object
159
+ */
160
+ createProtocolMeta(actionCode, issuer, params) {
161
+ return meta_1.ProtocolMetaParser.fromInitiator(actionCode.pubkey, issuer || actionCode.pubkey, actionCode.prefix, params);
162
+ }
163
+ /**
164
+ * Encode protocol meta for a specific chain
165
+ * @param meta - ProtocolMetaV1 object
166
+ * @param chain - Target chain
167
+ * @returns Chain-specific encoded meta
168
+ */
169
+ encodeProtocolMeta(meta, chain) {
170
+ const adapter = this.adapters.get(chain);
171
+ if (!adapter) {
172
+ throw new Error(`Chain '${chain}' is not supported`);
173
+ }
174
+ return adapter.encode(meta);
175
+ }
176
+ /**
177
+ * Decode protocol meta from a transaction
178
+ * @param transaction - Chain-specific transaction
179
+ * @param chain - Source chain
180
+ * @returns Decoded ProtocolMetaV1 or null
181
+ */
182
+ decodeProtocolMeta(transaction, chain) {
183
+ const adapter = this.adapters.get(chain);
184
+ if (!adapter) {
185
+ return null;
186
+ }
187
+ return adapter.decode(transaction);
188
+ }
189
+ /**
190
+ * Validate a transaction with protocol meta
191
+ * @param transaction - Chain-specific transaction
192
+ * @param chain - Source chain
193
+ * @param authorities - Array of valid protocol authority identifiers
194
+ * @param expectedPrefix - Expected protocol prefix
195
+ * @returns True if transaction is valid
196
+ */
197
+ validateTransaction(transaction, chain, authorities, expectedPrefix) {
198
+ const adapter = this.adapters.get(chain);
199
+ if (!adapter) {
200
+ return false;
201
+ }
202
+ return adapter.validate(transaction, authorities, expectedPrefix);
203
+ }
204
+ /**
205
+ * Type-safe transaction validation for specific chains
206
+ * @param transaction - Chain-specific transaction
207
+ * @param chain - Source chain
208
+ * @param authorities - Array of valid protocol authority identifiers
209
+ * @param expectedPrefix - Expected protocol prefix
210
+ * @returns True if transaction is valid
211
+ */
212
+ validateTransactionTyped(transaction, chain, authorities, expectedPrefix) {
213
+ const adapter = this.getChainAdapter(chain);
214
+ if (!adapter) {
215
+ return false;
216
+ }
217
+ return adapter.validate(transaction, authorities, expectedPrefix);
218
+ }
219
+ /**
220
+ * Detect tampered transactions with type safety
221
+ * @param transaction - Chain-specific transaction
222
+ * @param chain - Source chain
223
+ * @param authorities - Array of valid protocol authority identifiers
224
+ * @param expectedPrefix - Expected protocol prefix
225
+ * @returns True if transaction is valid and not tampered
226
+ */
227
+ detectTampering(transaction, chain, authorities, expectedPrefix) {
228
+ const adapter = this.getChainAdapter(chain);
229
+ if (!adapter) {
230
+ return false;
231
+ }
232
+ return adapter.detectTampering(transaction, authorities, expectedPrefix);
233
+ }
234
+ /**
235
+ * Decode protocol meta with type safety
236
+ * @param transaction - Chain-specific transaction
237
+ * @param chain - Source chain
238
+ * @returns Decoded ProtocolMetaV1 or null
239
+ */
240
+ decodeProtocolMetaTyped(transaction, chain) {
241
+ const adapter = this.getChainAdapter(chain);
242
+ if (!adapter) {
243
+ return null;
244
+ }
245
+ return adapter.decode(transaction);
246
+ }
247
+ /**
248
+ * Get protocol configuration
249
+ * @returns Current protocol configuration
250
+ */
251
+ getConfig() {
252
+ return { ...this.config };
253
+ }
254
+ /**
255
+ * Update protocol configuration
256
+ * @param updates - Configuration updates
257
+ */
258
+ updateConfig(updates) {
259
+ this.config = { ...this.config, ...updates };
260
+ }
261
+ /**
262
+ * Create a new protocol instance with default configuration
263
+ * @returns New protocol instance
264
+ */
265
+ static create() {
266
+ return new ActionCodesProtocol();
267
+ }
268
+ /**
269
+ * Create a new protocol instance with custom configuration
270
+ * @param config - Custom configuration
271
+ * @returns New protocol instance
272
+ */
273
+ static createWithConfig(config) {
274
+ return new ActionCodesProtocol(config);
275
+ }
276
+ }
277
+ exports.ActionCodesProtocol = ActionCodesProtocol;
278
+ // Export constants
279
+ var constants_2 = require("./constants");
280
+ Object.defineProperty(exports, "SUPPORTED_CHAINS", { enumerable: true, get: function () { return constants_2.SUPPORTED_CHAINS; } });
package/docs/README.md ADDED
@@ -0,0 +1,59 @@
1
+ **@actioncodes/protocol**
2
+
3
+ ***
4
+
5
+ # 🛡️ Action Codes Protocol
6
+
7
+ ![Coverage](https://img.shields.io/badge/coverage-99.25%25-brightgreen)
8
+
9
+ **Action Codes Protocol** enables short-lived, cryptographically verifiable action codes that authorize blockchain transactions and intents without requiring live wallet sessions.
10
+
11
+ This repository contains the canonical specifications, SDK modules, and chain adapter interfaces that implement the Action Codes Protocol.
12
+
13
+ ---
14
+
15
+ ## ✨ Key Features
16
+
17
+ - 🔐 **Deterministic Code Generation**
18
+ Users can generate time-limited codes directly in their wallet or client, without external servers.
19
+
20
+ - ✅ **Signature-Based Verification**
21
+ Codes are signed by the wallet, and transactions must be signed by protocol-authorized relayers.
22
+
23
+ - 🧩 **Meta-Based Intent Encoding**
24
+ Each transaction carries an encoded `meta` string for verifiable context across chains.
25
+
26
+ - 🧱 **Chain-Agnostic Design**
27
+ Works on Solana today; built for future EVM, Cosmos, and more.
28
+
29
+ - 🌐 **Prefix Namespace System**
30
+ Enables ecosystem-wide namespacing (e.g. `JUP`, `ME`) for branded intents and UIs.
31
+
32
+ ---
33
+
34
+ ## 📦 Repository Structure
35
+
36
+ ```
37
+ /src - SDK modules (codegen, meta, validator, blockchain adapters)
38
+ /specs - Formal specifications (AIPs)
39
+ README.md - You are here
40
+ LICENSE - Apache 2.0
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 📄 Specifications
46
+
47
+ [Protocol Specifications](_media/README.md)
48
+
49
+ - [`AIP-0`](./specs/aip-0.md): Action Codes Protocol Architecture
50
+ - [`AIP-1`](./specs/aip-1.md): Protocol Meta Format
51
+ - [`AIP-2`](./specs/aip-2.md): Authority Signature Validation
52
+ - [`AIP-3`](./specs/aip-3.md): Intent Resolution & Routing
53
+ - [`AIP-4`](./specs/aip-4.md): Prefix System
54
+
55
+ ---
56
+
57
+ ## 📜 License
58
+
59
+ This protocol is open source under the [Apache 2.0 License](_media/LICENSE).