@actioncodes/protocol 1.2.2 → 2.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 (144) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +32 -45
  3. package/dist/ActionCodesProtocol.d.ts +35 -0
  4. package/dist/ActionCodesProtocol.d.ts.map +1 -0
  5. package/dist/adapters/BaseChainAdapter.d.ts +22 -0
  6. package/dist/adapters/BaseChainAdapter.d.ts.map +1 -0
  7. package/dist/adapters/SolanaAdapter.d.ts +44 -0
  8. package/dist/adapters/SolanaAdapter.d.ts.map +1 -0
  9. package/dist/constants.d.ts +6 -8
  10. package/dist/constants.d.ts.map +1 -1
  11. package/dist/errors.d.ts +63 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/index.cjs +3 -0
  14. package/dist/index.cjs.map +25 -0
  15. package/dist/index.d.ts +10 -8
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -36
  18. package/dist/index.js.map +25 -0
  19. package/dist/strategy/DelegationStrategy.d.ts +43 -0
  20. package/dist/strategy/DelegationStrategy.d.ts.map +1 -0
  21. package/dist/strategy/WalletStrategy.d.ts +8 -0
  22. package/dist/strategy/WalletStrategy.d.ts.map +1 -0
  23. package/dist/types.d.ts +40 -0
  24. package/dist/types.d.ts.map +1 -0
  25. package/dist/utils/canonical.d.ts +5 -0
  26. package/dist/utils/canonical.d.ts.map +1 -0
  27. package/dist/utils/crypto.d.ts +13 -0
  28. package/dist/utils/crypto.d.ts.map +1 -0
  29. package/dist/utils/protocolMeta.d.ts +16 -0
  30. package/dist/utils/protocolMeta.d.ts.map +1 -0
  31. package/docs/ActionCodesProtocol/README.md +11 -0
  32. package/docs/ActionCodesProtocol/classes/ActionCodesProtocol.md +147 -0
  33. package/docs/README.md +10 -50
  34. package/docs/adapters/BaseChainAdapter/README.md +20 -0
  35. package/docs/adapters/BaseChainAdapter/classes/BaseChainAdapter.md +56 -0
  36. package/docs/adapters/BaseChainAdapter/interfaces/BaseContext.md +17 -0
  37. package/docs/adapters/BaseChainAdapter/interfaces/ChainAdapter.md +33 -0
  38. package/docs/adapters/BaseChainAdapter/type-aliases/ChainContext.md +23 -0
  39. package/docs/adapters/NodeCryptoAdapter/README.md +15 -0
  40. package/docs/adapters/NodeCryptoAdapter/classes/NodeCryptoAdapter.md +254 -0
  41. package/docs/adapters/NodeCryptoAdapter/type-aliases/NodeCryptoContext.md +27 -0
  42. package/docs/adapters/SolanaAdapter/README.md +16 -0
  43. package/docs/adapters/SolanaAdapter/classes/SolanaAdapter.md +190 -0
  44. package/docs/adapters/SolanaAdapter/type-aliases/SolanaContext.md +27 -0
  45. package/docs/adapters/SolanaAdapter/type-aliases/SolanaTransaction.md +13 -0
  46. package/docs/constants/README.md +8 -13
  47. package/docs/constants/variables/CODE_CHARSET_DIGITS.md +11 -0
  48. package/docs/constants/variables/CODE_DEFAULT_LENGTH.md +11 -0
  49. package/docs/constants/variables/CODE_MAX_LENGTH.md +11 -0
  50. package/docs/constants/variables/CODE_MIN_LENGTH.md +11 -0
  51. package/docs/constants/variables/PROTOCOL_META_MAX_BYTES.md +11 -0
  52. package/docs/constants/variables/PROTOCOL_NORMALIZATION.md +11 -0
  53. package/docs/constants/variables/SUPPORTED_CHAINS.md +3 -3
  54. package/docs/errors/README.md +22 -0
  55. package/docs/errors/classes/ExpiredCodeError.md +695 -0
  56. package/docs/errors/classes/InvalidCodeFormatError.md +691 -0
  57. package/docs/errors/classes/InvalidPubkeyFormatError.md +691 -0
  58. package/docs/errors/classes/InvalidSignatureError.md +687 -0
  59. package/docs/errors/classes/MetaMismatchError.md +695 -0
  60. package/docs/errors/classes/MissingMetaError.md +681 -0
  61. package/docs/errors/classes/ProtocolError.md +637 -0
  62. package/docs/errors/classes/TransactionNotSignedByIntendedOwnerError.md +691 -0
  63. package/docs/errors/enumerations/ProtocolErrorCode.md +121 -0
  64. package/docs/index/README.md +83 -41
  65. package/docs/modules.md +12 -9
  66. package/docs/strategy/WalletStrategy/README.md +11 -0
  67. package/docs/strategy/WalletStrategy/classes/WalletStrategy.md +67 -0
  68. package/docs/types/README.md +14 -0
  69. package/docs/types/interfaces/ActionCode.md +65 -0
  70. package/docs/types/interfaces/CanonicalMessageParts.md +33 -0
  71. package/docs/types/interfaces/CodeGenerationConfig.md +33 -0
  72. package/docs/types/interfaces/CodeGenerationResult.md +25 -0
  73. package/docs/utils/canonical/README.md +16 -0
  74. package/docs/utils/canonical/functions/serializeCanonical.md +21 -0
  75. package/docs/utils/canonical/variables/CANONICAL_MESSAGE_PREFIX.md +11 -0
  76. package/docs/utils/canonical/variables/CANONICAL_MESSAGE_VERSION.md +11 -0
  77. package/docs/utils/crypto/README.md +18 -0
  78. package/docs/utils/crypto/functions/base32EncodeCrockford.md +21 -0
  79. package/docs/utils/crypto/functions/codeHash.md +21 -0
  80. package/docs/utils/crypto/functions/digestToDigits.md +25 -0
  81. package/docs/utils/crypto/functions/generateRandomSecret.md +15 -0
  82. package/docs/utils/crypto/functions/hkdfSha256.md +35 -0
  83. package/docs/utils/crypto/functions/hmacSha256.md +25 -0
  84. package/docs/utils/crypto/functions/sha256.md +21 -0
  85. package/docs/utils/crypto/functions/truncateBits.md +25 -0
  86. package/docs/utils/protocolMeta/README.md +21 -0
  87. package/docs/utils/protocolMeta/functions/buildProtocolMeta.md +21 -0
  88. package/docs/utils/protocolMeta/functions/parseProtocolMeta.md +21 -0
  89. package/docs/utils/protocolMeta/functions/validateProtocolMetaFormat.md +21 -0
  90. package/docs/utils/protocolMeta/interfaces/ProtocolMetaFields.md +41 -0
  91. package/docs/utils/protocolMeta/variables/SCHEME.md +11 -0
  92. package/package.json +42 -47
  93. package/dist/actioncode.d.ts +0 -120
  94. package/dist/actioncode.d.ts.map +0 -1
  95. package/dist/actioncode.js +0 -186
  96. package/dist/adapters/base.d.ts +0 -93
  97. package/dist/adapters/base.d.ts.map +0 -1
  98. package/dist/adapters/base.js +0 -65
  99. package/dist/adapters/solana/index.d.ts +0 -2
  100. package/dist/adapters/solana/index.d.ts.map +0 -1
  101. package/dist/adapters/solana/index.js +0 -30
  102. package/dist/adapters/solana/solana.d.ts +0 -113
  103. package/dist/adapters/solana/solana.d.ts.map +0 -1
  104. package/dist/adapters/solana/solana.js +0 -537
  105. package/dist/codegen.d.ts +0 -76
  106. package/dist/codegen.d.ts.map +0 -1
  107. package/dist/codegen.js +0 -211
  108. package/dist/constants.js +0 -24
  109. package/dist/meta.d.ts +0 -54
  110. package/dist/meta.d.ts.map +0 -1
  111. package/dist/meta.js +0 -104
  112. package/dist/protocol.d.ts +0 -179
  113. package/dist/protocol.d.ts.map +0 -1
  114. package/dist/protocol.js +0 -390
  115. package/docs/_media/LICENSE +0 -201
  116. package/docs/_media/README.md +0 -28
  117. package/docs/actioncode/README.md +0 -21
  118. package/docs/actioncode/classes/ActionCode.md +0 -430
  119. package/docs/actioncode/interfaces/ActionCodeFields.md +0 -89
  120. package/docs/actioncode/interfaces/ActionCodeMetadata.md +0 -25
  121. package/docs/actioncode/interfaces/ActionCodeTransaction.md +0 -57
  122. package/docs/actioncode/type-aliases/ActionCodeStatus.md +0 -11
  123. package/docs/adapters/base/README.md +0 -11
  124. package/docs/adapters/base/classes/BaseChainAdapter.md +0 -396
  125. package/docs/adapters/solana/README.md +0 -19
  126. package/docs/adapters/solana/solana/README.md +0 -15
  127. package/docs/adapters/solana/solana/classes/SolanaAdapter.md +0 -506
  128. package/docs/adapters/solana/solana/type-aliases/SolanaTransaction.md +0 -13
  129. package/docs/codegen/README.md +0 -11
  130. package/docs/codegen/classes/CodeGenerator.md +0 -341
  131. package/docs/constants/type-aliases/SupportedChain.md +0 -11
  132. package/docs/constants/variables/CODE_LENGTH.md +0 -11
  133. package/docs/constants/variables/CODE_TTL.md +0 -11
  134. package/docs/constants/variables/MAX_PREFIX_LENGTH.md +0 -11
  135. package/docs/constants/variables/MIN_PREFIX_LENGTH.md +0 -11
  136. package/docs/constants/variables/PROTOCOL_CODE_PREFIX.md +0 -11
  137. package/docs/constants/variables/PROTOCOL_PREFIX.md +0 -11
  138. package/docs/constants/variables/PROTOCOL_VERSION.md +0 -11
  139. package/docs/meta/README.md +0 -15
  140. package/docs/meta/classes/ProtocolMetaParser.md +0 -177
  141. package/docs/meta/interfaces/ProtocolMetaV1.md +0 -59
  142. package/docs/protocol/README.md +0 -51
  143. package/docs/protocol/classes/ActionCodesProtocol.md +0 -676
  144. package/docs/protocol/interfaces/ProtocolConfig.md +0 -71
package/dist/codegen.js DELETED
@@ -1,211 +0,0 @@
1
- "use strict";
2
- // Copyright 2025 Trana, Inc.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.CodeGenerator = void 0;
17
- const js_sha256_1 = require("js-sha256");
18
- const constants_1 = require("./constants");
19
- class CodeGenerator {
20
- /**
21
- * Validate prefix format
22
- * @param prefix - The prefix to validate
23
- * @returns True if prefix is valid, false otherwise
24
- */
25
- static validatePrefix(prefix) {
26
- if (prefix === constants_1.PROTOCOL_CODE_PREFIX)
27
- return true;
28
- if (prefix.length < this.MIN_PREFIX_LENGTH || prefix.length > this.MAX_PREFIX_LENGTH)
29
- return false;
30
- return /^[A-Za-z]+$/.test(prefix);
31
- }
32
- /**
33
- * Validate generated code format (prefix + exactly 8 digits)
34
- * @param code - The code to validate
35
- * @returns True if code is valid, false otherwise
36
- */
37
- static validateCodeFormat(code) {
38
- if (!code || typeof code !== 'string')
39
- return false;
40
- // Code must be exactly prefix length + 8 digits
41
- if (code.length < this.CODE_DIGITS)
42
- return false;
43
- // Find where the numeric part starts (last 8 characters)
44
- const numericPart = code.slice(-this.CODE_DIGITS);
45
- const prefixPart = code.slice(0, -this.CODE_DIGITS);
46
- // Numeric part must be exactly 8 digits, no more, no less
47
- if (numericPart.length !== this.CODE_DIGITS)
48
- return false;
49
- if (!/^[0-9]{8}$/.test(numericPart))
50
- return false;
51
- // If there's a prefix part, validate it
52
- if (prefixPart.length > 0) {
53
- // Normalize the prefix for validation
54
- const normalizedPrefix = prefixPart.toUpperCase();
55
- if (normalizedPrefix === constants_1.PROTOCOL_CODE_PREFIX) {
56
- // DEFAULT prefix is valid but should be empty in normalized form
57
- return true;
58
- }
59
- // Check prefix length and format
60
- if (normalizedPrefix.length < this.MIN_PREFIX_LENGTH ||
61
- normalizedPrefix.length > this.MAX_PREFIX_LENGTH) {
62
- return false;
63
- }
64
- // Prefix must contain only letters
65
- if (!/^[A-Za-z]+$/.test(normalizedPrefix))
66
- return false;
67
- }
68
- return true;
69
- }
70
- /**
71
- * Validate that the numeric part of a code is exactly 8 digits
72
- * @param code - The code to validate (can include prefix)
73
- * @returns True if numeric part is valid, false otherwise
74
- */
75
- static validateCodeDigits(code) {
76
- if (!code || typeof code !== 'string')
77
- return false;
78
- if (code.length < constants_1.CODE_LENGTH)
79
- return false;
80
- // For codes without prefix, the entire code must be exactly 8 digits
81
- if (code.length === constants_1.CODE_LENGTH) {
82
- return /^[0-9]{8}$/.test(code);
83
- }
84
- // For codes with prefix, the total length must be prefix + 8 digits
85
- // and the last 8 characters must be digits
86
- const numericPart = code.slice(-constants_1.CODE_LENGTH);
87
- // Check if the numeric part is exactly 8 digits
88
- if (!/^[0-9]{8}$/.test(numericPart))
89
- return false;
90
- // Check if the prefix part (everything before the last 8 chars) is valid
91
- const prefixPart = code.slice(0, -constants_1.CODE_LENGTH);
92
- if (prefixPart.length > 0) {
93
- // Validate prefix format
94
- const normalizedPrefix = prefixPart.toUpperCase();
95
- if (normalizedPrefix === constants_1.PROTOCOL_CODE_PREFIX)
96
- return true;
97
- if (normalizedPrefix.length < this.MIN_PREFIX_LENGTH ||
98
- normalizedPrefix.length > this.MAX_PREFIX_LENGTH) {
99
- return false;
100
- }
101
- if (!/^[A-Za-z]+$/.test(normalizedPrefix))
102
- return false;
103
- }
104
- return true;
105
- }
106
- /**
107
- * Normalize prefix - convert PROTOCOL_CODE_PREFIX to empty string, validate others
108
- * @param prefix - The prefix to normalize
109
- * @returns Normalized prefix
110
- * @throws Error if prefix is invalid
111
- */
112
- static normalizePrefix(prefix) {
113
- if (prefix === constants_1.PROTOCOL_CODE_PREFIX)
114
- return "";
115
- if (!this.validatePrefix(prefix)) {
116
- throw new Error(`Invalid prefix: ${prefix}. Must be 3-12 letters or "${constants_1.PROTOCOL_CODE_PREFIX}"`);
117
- }
118
- return prefix.toUpperCase();
119
- }
120
- /**
121
- * Generate a deterministic 8-digit code based on public key, prefix, and timestamp
122
- * @param pubkey - Solana wallet public key (base58)
123
- * @param prefix - Optional namespace prefix (default: PROTOCOL_CODE_PREFIX)
124
- * @param timestamp - UNIX timestamp in milliseconds (defaults to now)
125
- * @returns Object containing code, issuedAt, and expiresAt timestamps
126
- * @throws Error if generated code is invalid
127
- */
128
- static generateCode(pubkey, prefix = constants_1.PROTOCOL_CODE_PREFIX, timestamp = Date.now()) {
129
- const normalizedPrefix = this.normalizePrefix(prefix);
130
- const input = `${normalizedPrefix}:${pubkey}:${timestamp}`;
131
- const hash = (0, js_sha256_1.sha256)(input);
132
- const raw = parseInt(hash.slice(0, 16), 16);
133
- const mod = 10 ** this.CODE_DIGITS;
134
- const code = raw % mod;
135
- const issuedAt = timestamp;
136
- const expiresAt = issuedAt + this.TIME_WINDOW_MS;
137
- const generatedCode = code.toString().padStart(this.CODE_DIGITS, "0");
138
- // Create the full code with prefix
139
- const fullCode = normalizedPrefix + generatedCode;
140
- // Validate the generated code
141
- if (!this.validateCodeFormat(fullCode)) {
142
- throw new Error(`Generated code validation failed: ${fullCode}`);
143
- }
144
- if (!this.validateCodeDigits(fullCode)) {
145
- throw new Error(`Generated code must be exactly 8 digits: ${fullCode}`);
146
- }
147
- return {
148
- code: fullCode,
149
- issuedAt,
150
- expiresAt
151
- };
152
- }
153
- /**
154
- * Derive the full SHA-256 hash for storage or encryption key generation
155
- * @param pubkey - Solana wallet public key (base58)
156
- * @param prefix - Optional namespace prefix (default: PROTOCOL_CODE_PREFIX)
157
- * @param timestamp - UNIX timestamp in milliseconds (defaults to now)
158
- * @returns Full SHA-256 hash string
159
- */
160
- static deriveCodeHash(pubkey, prefix = constants_1.PROTOCOL_CODE_PREFIX, timestamp) {
161
- const normalizedPrefix = this.normalizePrefix(prefix);
162
- const ts = timestamp ?? Date.now();
163
- const input = `${normalizedPrefix}:${pubkey}:${ts}`;
164
- const hash = (0, js_sha256_1.sha256)(input);
165
- return hash;
166
- }
167
- /**
168
- * Get the expected code for a given public key and timestamp
169
- * @param pubkey - Solana wallet public key (base58)
170
- * @param timestamp - UNIX timestamp in milliseconds
171
- * @param prefix - Optional namespace prefix (default: PROTOCOL_CODE_PREFIX)
172
- * @returns Full code string with prefix + 8 digits
173
- */
174
- static getExpectedCode(pubkey, timestamp, prefix = constants_1.PROTOCOL_CODE_PREFIX) {
175
- return this.generateCode(pubkey, prefix, timestamp).code;
176
- }
177
- /**
178
- * Validate if a code matches the expected code for a given public key and timestamp
179
- * @param code - The code to validate (can include prefix)
180
- * @param pubkey - Solana wallet public key (base58)
181
- * @param timestamp - UNIX timestamp in milliseconds
182
- * @param prefix - Optional namespace prefix (default: PROTOCOL_CODE_PREFIX)
183
- * @returns True if code matches expected code and timestamp is valid
184
- */
185
- static validateCode(code, pubkey, timestamp, prefix = constants_1.PROTOCOL_CODE_PREFIX) {
186
- // First validate the code format
187
- if (!this.validateCodeFormat(code)) {
188
- return false;
189
- }
190
- if (!this.validateCodeDigits(code)) {
191
- return false;
192
- }
193
- const expectedCode = this.getExpectedCode(pubkey, timestamp, prefix);
194
- const now = Date.now();
195
- const isTimeValid = timestamp >= 0 && timestamp <= now && now <= timestamp + this.TIME_WINDOW_MS;
196
- return code === expectedCode && isTimeValid;
197
- }
198
- /**
199
- * Check if a timestamp falls within a valid time window
200
- * @param timestamp - UNIX timestamp in milliseconds
201
- * @returns True if timestamp is valid
202
- */
203
- static isValidTimestamp(timestamp) {
204
- return timestamp >= 0 && timestamp <= Date.now() + this.TIME_WINDOW_MS;
205
- }
206
- }
207
- exports.CodeGenerator = CodeGenerator;
208
- CodeGenerator.TIME_WINDOW_MS = constants_1.CODE_TTL;
209
- CodeGenerator.CODE_DIGITS = constants_1.CODE_LENGTH;
210
- CodeGenerator.MIN_PREFIX_LENGTH = constants_1.MIN_PREFIX_LENGTH;
211
- CodeGenerator.MAX_PREFIX_LENGTH = constants_1.MAX_PREFIX_LENGTH;
package/dist/constants.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- // Copyright 2025 Trana, Inc.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.SUPPORTED_CHAINS = exports.MAX_PREFIX_LENGTH = exports.MIN_PREFIX_LENGTH = exports.PROTOCOL_CODE_PREFIX = exports.CODE_TTL = exports.CODE_LENGTH = exports.PROTOCOL_PREFIX = exports.PROTOCOL_VERSION = void 0;
17
- exports.PROTOCOL_VERSION = "1";
18
- exports.PROTOCOL_PREFIX = "actioncodes";
19
- exports.CODE_LENGTH = 8;
20
- exports.CODE_TTL = 1000 * 60 * 2; // 2 minutes
21
- exports.PROTOCOL_CODE_PREFIX = "DEFAULT";
22
- exports.MIN_PREFIX_LENGTH = 3;
23
- exports.MAX_PREFIX_LENGTH = 12;
24
- exports.SUPPORTED_CHAINS = ["solana"];
package/dist/meta.d.ts DELETED
@@ -1,54 +0,0 @@
1
- /**
2
- * Protocol meta structure for code verification
3
- */
4
- export interface ProtocolMetaV1 {
5
- version: string;
6
- prefix: string;
7
- initiator: string;
8
- id: string;
9
- iss?: string;
10
- params?: string;
11
- }
12
- /**
13
- * Protocol meta parser for structured memo/message parsing
14
- */
15
- export declare class ProtocolMetaParser {
16
- private static readonly PROTOCOL_REGEX;
17
- /**
18
- * Parse protocol meta from string
19
- * @param metaString - The protocol meta string to parse
20
- * @returns Parsed ProtocolMeta object or null if invalid
21
- */
22
- static parse(metaString: string): ProtocolMetaV1 | null;
23
- /**
24
- * Serialize ProtocolMeta to string
25
- * @param meta - The protocol meta to serialize
26
- * @returns Serialized protocol meta string
27
- */
28
- static serialize(meta: ProtocolMetaV1): string;
29
- /**
30
- * Create protocol meta from code and parameters
31
- * @param initiator - The initiator public key
32
- * @param iss - The issuer (protocol authority)
33
- * @param prefix - The prefix (default: "DEFAULT")
34
- * @param params - Optional parameters
35
- * @param timestamp - Optional timestamp
36
- * @returns ProtocolMeta object
37
- */
38
- static fromInitiator(initiator: string, iss: string, prefix?: string, params?: string, timestamp?: number): ProtocolMetaV1;
39
- /**
40
- * Validate if a code matches the protocol meta
41
- * @param meta - The protocol meta to validate against
42
- * @param timestamp - Optional timestamp for validation (if not provided, uses current time)
43
- * @returns True if the meta is valid
44
- */
45
- static validateCode(meta: ProtocolMetaV1, timestamp?: number): boolean;
46
- /**
47
- * Validate if a code matches the protocol meta by parsing from string
48
- * @param metaString - The protocol meta string to validate against
49
- * @param timestamp - Optional timestamp for validation (if not provided, uses current time)
50
- * @returns True if the code matches the meta
51
- */
52
- static validateMetaFromString(metaString: string, timestamp?: number): boolean;
53
- }
54
- //# sourceMappingURL=meta.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAiBA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAqF;IAE3H;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAuBvD;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM;IAU9C;;;;;;;;OAQG;IACH,MAAM,CAAC,aAAa,CAClB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAkB,EAC1B,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,GACjB,cAAc;IAajB;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO;IAKtE;;;;;OAKG;IACH,MAAM,CAAC,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO;CAO/E"}
package/dist/meta.js DELETED
@@ -1,104 +0,0 @@
1
- "use strict";
2
- // Copyright 2025 Trana, Inc.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.ProtocolMetaParser = void 0;
17
- const codegen_1 = require("./codegen");
18
- const constants_1 = require("./constants");
19
- /**
20
- * Protocol meta parser for structured memo/message parsing
21
- */
22
- class ProtocolMetaParser {
23
- /**
24
- * Parse protocol meta from string
25
- * @param metaString - The protocol meta string to parse
26
- * @returns Parsed ProtocolMeta object or null if invalid
27
- */
28
- static parse(metaString) {
29
- const match = metaString.match(this.PROTOCOL_REGEX);
30
- if (!match) {
31
- return null;
32
- }
33
- const [, protocolPrefix, version, prefix, initiator, id, iss, params] = match;
34
- // Validate protocol prefix
35
- if (protocolPrefix !== constants_1.PROTOCOL_PREFIX) {
36
- return null;
37
- }
38
- return {
39
- version,
40
- prefix,
41
- initiator,
42
- id,
43
- iss,
44
- params: params || undefined
45
- };
46
- }
47
- /**
48
- * Serialize ProtocolMeta to string
49
- * @param meta - The protocol meta to serialize
50
- * @returns Serialized protocol meta string
51
- */
52
- static serialize(meta) {
53
- let result = `${constants_1.PROTOCOL_PREFIX}:v=${meta.version}&pre=${meta.prefix}&ini=${meta.initiator}&id=${meta.id}&iss=${meta.iss}`;
54
- if (meta.params) {
55
- result += `&p=${meta.params}`;
56
- }
57
- return result;
58
- }
59
- /**
60
- * Create protocol meta from code and parameters
61
- * @param initiator - The initiator public key
62
- * @param iss - The issuer (protocol authority)
63
- * @param prefix - The prefix (default: "DEFAULT")
64
- * @param params - Optional parameters
65
- * @param timestamp - Optional timestamp
66
- * @returns ProtocolMeta object
67
- */
68
- static fromInitiator(initiator, iss, prefix = "DEFAULT", params, timestamp) {
69
- const codeHash = codegen_1.CodeGenerator.deriveCodeHash(initiator, prefix, timestamp);
70
- return {
71
- version: constants_1.PROTOCOL_VERSION,
72
- prefix,
73
- initiator,
74
- id: codeHash,
75
- iss,
76
- params
77
- };
78
- }
79
- /**
80
- * Validate if a code matches the protocol meta
81
- * @param meta - The protocol meta to validate against
82
- * @param timestamp - Optional timestamp for validation (if not provided, uses current time)
83
- * @returns True if the meta is valid
84
- */
85
- static validateCode(meta, timestamp) {
86
- const expectedHash = codegen_1.CodeGenerator.deriveCodeHash(meta.initiator, meta.prefix, timestamp);
87
- return meta.id === expectedHash;
88
- }
89
- /**
90
- * Validate if a code matches the protocol meta by parsing from string
91
- * @param metaString - The protocol meta string to validate against
92
- * @param timestamp - Optional timestamp for validation (if not provided, uses current time)
93
- * @returns True if the code matches the meta
94
- */
95
- static validateMetaFromString(metaString, timestamp) {
96
- const meta = this.parse(metaString);
97
- if (!meta) {
98
- return false;
99
- }
100
- return this.validateCode(meta, timestamp);
101
- }
102
- }
103
- exports.ProtocolMetaParser = ProtocolMetaParser;
104
- ProtocolMetaParser.PROTOCOL_REGEX = /^([^:]+):v=(\d+)&pre=([^&]*)&ini=([^&]*)&id=([^&]*)&iss=([^&]+)(?:&p=([^&]+))?$/;
@@ -1,179 +0,0 @@
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
- * Validate an action code, checking intent type and required fields
56
- * @param actionCode - ActionCode to validate
57
- * @returns True if valid
58
- */
59
- validateActionCode(actionCode: ActionCode): boolean;
60
- /**
61
- * Create an action code
62
- * @param pubkey - Wallet public key
63
- * @param signFn - Chain-specific signing function (e.g.wallet.signMessage)
64
- * @param chain - Target blockchain
65
- * @param prefix - Optional code prefix
66
- * @param timestamp - Optional timestamp
67
- * @returns Promise resolving to a complete ActionCode object
68
- */
69
- createActionCode(pubkey: string, signFn: (message: string) => Promise<string>, chain: SupportedChain, prefix?: string, timestamp?: number): Promise<ActionCode>;
70
- /**
71
- * Attach a transaction to an action code with automatic protocol meta injection
72
- * @param actionCode - ActionCode to attach transaction to
73
- * @param transaction - Chain-specific transaction data (serialized)
74
- * @param issuer - Issuer public key for protocol meta, this is the proof of who is attaching the transaction to the action code
75
- * @param params - Optional parameters for protocol meta
76
- * @param txType - Optional transaction type
77
- * @returns Updated ActionCode with injected protocol meta
78
- */
79
- attachTransaction(actionCode: ActionCode, transaction: string, issuer: string, params?: string, txType?: string): ActionCode;
80
- /**
81
- * Attach a message to an action code (sign-only mode, resolved state)
82
- * @param actionCode - ActionCode to attach message to
83
- * @param message - The message that will be signed
84
- * @param params - Optional parameters for protocol meta
85
- * @param messageType - Optional message type
86
- * @returns Updated ActionCode with transaction containing message
87
- */
88
- attachMessage(actionCode: ActionCode, message: string, params?: string, messageType?: string): ActionCode;
89
- /**
90
- * Finalize an action code based on its intent type
91
- * @param actionCode - ActionCode to finalize
92
- * @param signature - Transaction signature (for transaction intent) or signed message (for sign-only intent)
93
- * @returns Updated ActionCode
94
- */
95
- finalizeActionCode(actionCode: ActionCode, signature: string): ActionCode;
96
- /**
97
- * Create protocol meta for a transaction
98
- * @param actionCode - ActionCode to create meta for
99
- * @param issuer - Optional issuer public key
100
- * @param params - Optional parameters
101
- * @param timestamp - Optional timestamp (defaults to action code timestamp)
102
- * @returns ProtocolMetaV1 object
103
- */
104
- createProtocolMeta(actionCode: ActionCode, issuer?: string, params?: string, timestamp?: number): ProtocolMetaV1;
105
- /**
106
- * Encode protocol meta for a specific chain
107
- * @param meta - ProtocolMetaV1 object
108
- * @param chain - Target chain
109
- * @returns Chain-specific encoded meta
110
- */
111
- encodeProtocolMeta(meta: ProtocolMetaV1, chain: string): any;
112
- /**
113
- * Decode protocol meta from a transaction
114
- * @param transaction - Chain-specific transaction
115
- * @param chain - Source chain
116
- * @returns Decoded ProtocolMetaV1 or null
117
- */
118
- decodeProtocolMeta(transaction: any, chain: string): ProtocolMetaV1 | null;
119
- /**
120
- * Validate a transaction with protocol meta
121
- * @param transaction - Chain-specific transaction (can be serialized string or deserialized object)
122
- * @param chain - Source chain
123
- * @param authorities - Array of valid protocol authority identifiers
124
- * @param expectedPrefix - Expected protocol prefix
125
- * @returns True if transaction is valid
126
- */
127
- validateTransaction(transaction: any, chain: string, authorities: string[], expectedPrefix?: string): boolean;
128
- /**
129
- * Type-safe transaction validation for specific chains
130
- * @param transaction - Chain-specific transaction
131
- * @param chain - Source chain
132
- * @param authorities - Array of valid protocol authority identifiers
133
- * @param expectedPrefix - Expected protocol prefix
134
- * @returns True if transaction is valid
135
- */
136
- validateTransactionTyped<T>(transaction: T, chain: string, authorities: string[], expectedPrefix?: string): boolean;
137
- /**
138
- * Detect tampered transactions with type safety
139
- * @param transaction - Chain-specific transaction
140
- * @param chain - Source chain
141
- * @param authorities - Array of valid protocol authority identifiers
142
- * @param expectedPrefix - Expected protocol prefix
143
- * @returns True if transaction is valid and not tampered
144
- */
145
- detectTampering<T>(transaction: T, chain: string, authorities: string[], expectedPrefix?: string): boolean;
146
- /**
147
- * Decode protocol meta with type safety
148
- * @param transaction - Chain-specific transaction
149
- * @param chain - Source chain
150
- * @returns Decoded ProtocolMetaV1 or null
151
- */
152
- decodeProtocolMetaTyped<T>(transaction: T, chain: string): ProtocolMetaV1 | null;
153
- /**
154
- * Get protocol configuration
155
- * @returns Current protocol configuration
156
- */
157
- getConfig(): ProtocolConfig;
158
- /**
159
- * Update protocol configuration
160
- * @param updates - Configuration updates
161
- */
162
- updateConfig(updates: Partial<ProtocolConfig>): void;
163
- /**
164
- * Create a new protocol instance with default configuration
165
- * @returns New protocol instance
166
- */
167
- static create(): ActionCodesProtocol;
168
- /**
169
- * Create a new protocol instance with custom configuration
170
- * @param config - Custom configuration
171
- * @returns New protocol instance
172
- */
173
- static createWithConfig(config: Partial<ProtocolConfig>): ActionCodesProtocol;
174
- }
175
- export type { ActionCode, ActionCodeStatus, ActionCodeTransaction } from './actioncode';
176
- export type { ProtocolMetaV1 } from './meta';
177
- export { SUPPORTED_CHAINS } from './constants';
178
- export type { SupportedChain } from './constants';
179
- //# sourceMappingURL=protocol.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAeA,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;I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