@actioncodes/protocol 1.2.1 → 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 +2 -2
  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 -23
  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 -173
  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 -52
  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 -17
  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 -524
  105. package/dist/codegen.d.ts +0 -76
  106. package/dist/codegen.d.ts.map +0 -1
  107. package/dist/codegen.js +0 -198
  108. package/dist/constants.js +0 -11
  109. package/dist/meta.d.ts +0 -54
  110. package/dist/meta.d.ts.map +0 -1
  111. package/dist/meta.js +0 -91
  112. package/dist/protocol.d.ts +0 -179
  113. package/dist/protocol.d.ts.map +0 -1
  114. package/dist/protocol.js +0 -377
  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,198 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CodeGenerator = void 0;
4
- const js_sha256_1 = require("js-sha256");
5
- const constants_1 = require("./constants");
6
- class CodeGenerator {
7
- /**
8
- * Validate prefix format
9
- * @param prefix - The prefix to validate
10
- * @returns True if prefix is valid, false otherwise
11
- */
12
- static validatePrefix(prefix) {
13
- if (prefix === constants_1.PROTOCOL_CODE_PREFIX)
14
- return true;
15
- if (prefix.length < this.MIN_PREFIX_LENGTH || prefix.length > this.MAX_PREFIX_LENGTH)
16
- return false;
17
- return /^[A-Za-z]+$/.test(prefix);
18
- }
19
- /**
20
- * Validate generated code format (prefix + exactly 8 digits)
21
- * @param code - The code to validate
22
- * @returns True if code is valid, false otherwise
23
- */
24
- static validateCodeFormat(code) {
25
- if (!code || typeof code !== 'string')
26
- return false;
27
- // Code must be exactly prefix length + 8 digits
28
- if (code.length < this.CODE_DIGITS)
29
- return false;
30
- // Find where the numeric part starts (last 8 characters)
31
- const numericPart = code.slice(-this.CODE_DIGITS);
32
- const prefixPart = code.slice(0, -this.CODE_DIGITS);
33
- // Numeric part must be exactly 8 digits, no more, no less
34
- if (numericPart.length !== this.CODE_DIGITS)
35
- return false;
36
- if (!/^[0-9]{8}$/.test(numericPart))
37
- return false;
38
- // If there's a prefix part, validate it
39
- if (prefixPart.length > 0) {
40
- // Normalize the prefix for validation
41
- const normalizedPrefix = prefixPart.toUpperCase();
42
- if (normalizedPrefix === constants_1.PROTOCOL_CODE_PREFIX) {
43
- // DEFAULT prefix is valid but should be empty in normalized form
44
- return true;
45
- }
46
- // Check prefix length and format
47
- if (normalizedPrefix.length < this.MIN_PREFIX_LENGTH ||
48
- normalizedPrefix.length > this.MAX_PREFIX_LENGTH) {
49
- return false;
50
- }
51
- // Prefix must contain only letters
52
- if (!/^[A-Za-z]+$/.test(normalizedPrefix))
53
- return false;
54
- }
55
- return true;
56
- }
57
- /**
58
- * Validate that the numeric part of a code is exactly 8 digits
59
- * @param code - The code to validate (can include prefix)
60
- * @returns True if numeric part is valid, false otherwise
61
- */
62
- static validateCodeDigits(code) {
63
- if (!code || typeof code !== 'string')
64
- return false;
65
- if (code.length < constants_1.CODE_LENGTH)
66
- return false;
67
- // For codes without prefix, the entire code must be exactly 8 digits
68
- if (code.length === constants_1.CODE_LENGTH) {
69
- return /^[0-9]{8}$/.test(code);
70
- }
71
- // For codes with prefix, the total length must be prefix + 8 digits
72
- // and the last 8 characters must be digits
73
- const numericPart = code.slice(-constants_1.CODE_LENGTH);
74
- // Check if the numeric part is exactly 8 digits
75
- if (!/^[0-9]{8}$/.test(numericPart))
76
- return false;
77
- // Check if the prefix part (everything before the last 8 chars) is valid
78
- const prefixPart = code.slice(0, -constants_1.CODE_LENGTH);
79
- if (prefixPart.length > 0) {
80
- // Validate prefix format
81
- const normalizedPrefix = prefixPart.toUpperCase();
82
- if (normalizedPrefix === constants_1.PROTOCOL_CODE_PREFIX)
83
- return true;
84
- if (normalizedPrefix.length < this.MIN_PREFIX_LENGTH ||
85
- normalizedPrefix.length > this.MAX_PREFIX_LENGTH) {
86
- return false;
87
- }
88
- if (!/^[A-Za-z]+$/.test(normalizedPrefix))
89
- return false;
90
- }
91
- return true;
92
- }
93
- /**
94
- * Normalize prefix - convert PROTOCOL_CODE_PREFIX to empty string, validate others
95
- * @param prefix - The prefix to normalize
96
- * @returns Normalized prefix
97
- * @throws Error if prefix is invalid
98
- */
99
- static normalizePrefix(prefix) {
100
- if (prefix === constants_1.PROTOCOL_CODE_PREFIX)
101
- return "";
102
- if (!this.validatePrefix(prefix)) {
103
- throw new Error(`Invalid prefix: ${prefix}. Must be 3-12 letters or "${constants_1.PROTOCOL_CODE_PREFIX}"`);
104
- }
105
- return prefix.toUpperCase();
106
- }
107
- /**
108
- * Generate a deterministic 8-digit code based on public key, prefix, and timestamp
109
- * @param pubkey - Solana wallet public key (base58)
110
- * @param prefix - Optional namespace prefix (default: PROTOCOL_CODE_PREFIX)
111
- * @param timestamp - UNIX timestamp in milliseconds (defaults to now)
112
- * @returns Object containing code, issuedAt, and expiresAt timestamps
113
- * @throws Error if generated code is invalid
114
- */
115
- static generateCode(pubkey, prefix = constants_1.PROTOCOL_CODE_PREFIX, timestamp = Date.now()) {
116
- const normalizedPrefix = this.normalizePrefix(prefix);
117
- const input = `${normalizedPrefix}:${pubkey}:${timestamp}`;
118
- const hash = (0, js_sha256_1.sha256)(input);
119
- const raw = parseInt(hash.slice(0, 16), 16);
120
- const mod = 10 ** this.CODE_DIGITS;
121
- const code = raw % mod;
122
- const issuedAt = timestamp;
123
- const expiresAt = issuedAt + this.TIME_WINDOW_MS;
124
- const generatedCode = code.toString().padStart(this.CODE_DIGITS, "0");
125
- // Create the full code with prefix
126
- const fullCode = normalizedPrefix + generatedCode;
127
- // Validate the generated code
128
- if (!this.validateCodeFormat(fullCode)) {
129
- throw new Error(`Generated code validation failed: ${fullCode}`);
130
- }
131
- if (!this.validateCodeDigits(fullCode)) {
132
- throw new Error(`Generated code must be exactly 8 digits: ${fullCode}`);
133
- }
134
- return {
135
- code: fullCode,
136
- issuedAt,
137
- expiresAt
138
- };
139
- }
140
- /**
141
- * Derive the full SHA-256 hash for storage or encryption key generation
142
- * @param pubkey - Solana wallet public key (base58)
143
- * @param prefix - Optional namespace prefix (default: PROTOCOL_CODE_PREFIX)
144
- * @param timestamp - UNIX timestamp in milliseconds (defaults to now)
145
- * @returns Full SHA-256 hash string
146
- */
147
- static deriveCodeHash(pubkey, prefix = constants_1.PROTOCOL_CODE_PREFIX, timestamp) {
148
- const normalizedPrefix = this.normalizePrefix(prefix);
149
- const ts = timestamp ?? Date.now();
150
- const input = `${normalizedPrefix}:${pubkey}:${ts}`;
151
- const hash = (0, js_sha256_1.sha256)(input);
152
- return hash;
153
- }
154
- /**
155
- * Get the expected code for a given public key and timestamp
156
- * @param pubkey - Solana wallet public key (base58)
157
- * @param timestamp - UNIX timestamp in milliseconds
158
- * @param prefix - Optional namespace prefix (default: PROTOCOL_CODE_PREFIX)
159
- * @returns Full code string with prefix + 8 digits
160
- */
161
- static getExpectedCode(pubkey, timestamp, prefix = constants_1.PROTOCOL_CODE_PREFIX) {
162
- return this.generateCode(pubkey, prefix, timestamp).code;
163
- }
164
- /**
165
- * Validate if a code matches the expected code for a given public key and timestamp
166
- * @param code - The code to validate (can include prefix)
167
- * @param pubkey - Solana wallet public key (base58)
168
- * @param timestamp - UNIX timestamp in milliseconds
169
- * @param prefix - Optional namespace prefix (default: PROTOCOL_CODE_PREFIX)
170
- * @returns True if code matches expected code and timestamp is valid
171
- */
172
- static validateCode(code, pubkey, timestamp, prefix = constants_1.PROTOCOL_CODE_PREFIX) {
173
- // First validate the code format
174
- if (!this.validateCodeFormat(code)) {
175
- return false;
176
- }
177
- if (!this.validateCodeDigits(code)) {
178
- return false;
179
- }
180
- const expectedCode = this.getExpectedCode(pubkey, timestamp, prefix);
181
- const now = Date.now();
182
- const isTimeValid = timestamp >= 0 && timestamp <= now && now <= timestamp + this.TIME_WINDOW_MS;
183
- return code === expectedCode && isTimeValid;
184
- }
185
- /**
186
- * Check if a timestamp falls within a valid time window
187
- * @param timestamp - UNIX timestamp in milliseconds
188
- * @returns True if timestamp is valid
189
- */
190
- static isValidTimestamp(timestamp) {
191
- return timestamp >= 0 && timestamp <= Date.now() + this.TIME_WINDOW_MS;
192
- }
193
- }
194
- exports.CodeGenerator = CodeGenerator;
195
- CodeGenerator.TIME_WINDOW_MS = constants_1.CODE_TTL;
196
- CodeGenerator.CODE_DIGITS = constants_1.CODE_LENGTH;
197
- CodeGenerator.MIN_PREFIX_LENGTH = constants_1.MIN_PREFIX_LENGTH;
198
- CodeGenerator.MAX_PREFIX_LENGTH = constants_1.MAX_PREFIX_LENGTH;
package/dist/constants.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- 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;
4
- exports.PROTOCOL_VERSION = "1";
5
- exports.PROTOCOL_PREFIX = "actioncodes";
6
- exports.CODE_LENGTH = 8;
7
- exports.CODE_TTL = 1000 * 60 * 2; // 2 minutes
8
- exports.PROTOCOL_CODE_PREFIX = "DEFAULT";
9
- exports.MIN_PREFIX_LENGTH = 3;
10
- exports.MAX_PREFIX_LENGTH = 12;
11
- 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":"AAGA;;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,91 +0,0 @@
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=([^&]+))?$/;
@@ -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":"AACA,OAAO,EAAsB,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,UAAU,EAA2C,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,gBA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