@actioncodes/protocol 1.2.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +318 -33
  3. package/dist/ActionCodesProtocol.d.ts +37 -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 +45 -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
@@ -1,186 +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.ActionCode = void 0;
17
- const codegen_1 = require("./codegen");
18
- const buffer_1 = require("buffer");
19
- class ActionCode {
20
- constructor(fields) {
21
- this.fields = fields;
22
- }
23
- static fromPayload(input) {
24
- if (!input.code || !input.pubkey || !input.signature || !input.timestamp || !input.expiresAt || !input.chain || !input.status) {
25
- throw new Error("Missing required fields in ActionCode payload");
26
- }
27
- return new ActionCode(input);
28
- }
29
- static fromEncoded(encoded) {
30
- const decoded = JSON.parse(buffer_1.Buffer.from(encoded, 'base64').toString('utf8'));
31
- return ActionCode.fromPayload(decoded);
32
- }
33
- get encoded() {
34
- return buffer_1.Buffer.from(JSON.stringify(this.fields), 'utf8').toString('base64');
35
- }
36
- isValid(protocol) {
37
- if (this.expired)
38
- return false;
39
- const adapter = protocol.getChainAdapter(this.chain);
40
- if (!adapter)
41
- throw new Error(`Chain adapter not found for chain ${this.chain}`);
42
- const isSignatureValid = adapter.verifyCodeSignature(this);
43
- const isCodeValid = codegen_1.CodeGenerator.validateCode(this.fields.code, this.fields.pubkey, this.fields.timestamp, this.fields.prefix);
44
- return isSignatureValid && isCodeValid;
45
- }
46
- updateStatus(status) {
47
- this.fields.status = status;
48
- }
49
- get json() {
50
- return this.fields;
51
- }
52
- // UX-focused helper methods
53
- /**
54
- * Get remaining time in milliseconds until expiration
55
- * @returns Remaining time in milliseconds, or 0 if expired
56
- */
57
- get remainingTime() {
58
- const now = Date.now();
59
- return Math.max(0, this.fields.expiresAt - now); // TODO: rename to remainingTime
60
- }
61
- /**
62
- * Check if the action code has expired
63
- * @returns True if the code has expired
64
- */
65
- get expired() {
66
- return this.remainingTime === 0; // TODO: rename to expired
67
- }
68
- /**
69
- * Get the target chain for this action code
70
- * @returns Chain identifier (e.g., "solana", "evm")
71
- */
72
- get chain() {
73
- return this.fields.chain;
74
- }
75
- /**
76
- * Get the current status of the action code
77
- * @returns Current status
78
- */
79
- get status() {
80
- return this.fields.status;
81
- }
82
- /**
83
- * Get the action code string
84
- * @returns The 8-character action code
85
- */
86
- get code() {
87
- return this.fields.code;
88
- }
89
- /**
90
- * Get the prefix used for this action code
91
- * @returns Normalized prefix
92
- */
93
- get prefix() {
94
- return this.fields.prefix;
95
- }
96
- /**
97
- * Get the user's public key
98
- * @returns User's public key
99
- */
100
- get pubkey() {
101
- return this.fields.pubkey;
102
- }
103
- /**
104
- * Get the transaction data (chain-specific)
105
- * @returns Transaction data or undefined
106
- */
107
- get transaction() {
108
- return this.fields.transaction;
109
- }
110
- /**
111
- * Get metadata associated with this action code
112
- * @returns Metadata object or undefined
113
- */
114
- get metadata() {
115
- return this.fields.metadata;
116
- }
117
- /**
118
- * Get a human-readable description of the action
119
- * @returns Description string or undefined
120
- */
121
- get description() {
122
- return this.fields.metadata?.description;
123
- }
124
- /**
125
- * Get parameters associated with this action
126
- * @returns Parameters object or undefined
127
- */
128
- get params() {
129
- return this.fields.metadata?.params;
130
- }
131
- /**
132
- * Get the timestamp when the code was generated
133
- * @returns Timestamp in milliseconds
134
- */
135
- get timestamp() {
136
- return this.fields.timestamp;
137
- }
138
- /**
139
- * Get the user's signature
140
- * @returns User's signature string
141
- */
142
- get signature() {
143
- return this.fields.signature;
144
- }
145
- /**
146
- * Get a human-readable display string for the action code
147
- * @returns Formatted display string
148
- */
149
- get displayString() {
150
- const prefix = this.fields.prefix === 'DEFAULT' ? '' : `${this.fields.prefix}-`;
151
- const code = this.fields.code;
152
- const chain = this.fields.chain;
153
- const status = this.fields.status;
154
- return `${prefix}${code} (${chain}, ${status})`;
155
- }
156
- /**
157
- * Get a formatted time string showing remaining time
158
- * @returns Human-readable time string (e.g., "1m 30s remaining")
159
- */
160
- get remainingTimeString() {
161
- const remaining = this.remainingTime;
162
- if (remaining === 0) {
163
- return 'Expired';
164
- }
165
- const minutes = Math.floor(remaining / 60000);
166
- const seconds = Math.floor((remaining % 60000) / 1000);
167
- if (minutes > 0) {
168
- return `${minutes}m ${seconds}s remaining`;
169
- }
170
- else {
171
- return `${seconds}s remaining`;
172
- }
173
- }
174
- /**
175
- * Get the code hash for this action code
176
- * it is also used in the protocol meta as the code id
177
- * @returns Code hash string
178
- */
179
- get codeHash() {
180
- return codegen_1.CodeGenerator.deriveCodeHash(this.fields.pubkey, this.fields.prefix, this.fields.timestamp);
181
- }
182
- get intentType() {
183
- return this.fields.transaction?.intentType || 'transaction';
184
- }
185
- }
186
- exports.ActionCode = ActionCode;
@@ -1,93 +0,0 @@
1
- import { ActionCode } from '../actioncode';
2
- import { ProtocolMetaV1 } from '../meta';
3
- /**
4
- * Base adapter class for chain-specific protocol meta operations
5
- * @template T - Chain-specific transaction type
6
- */
7
- export declare abstract class BaseChainAdapter<T = any> {
8
- abstract readonly chain: string;
9
- /**
10
- * Encode protocol meta for this chain
11
- * @param meta - ProtocolMetaV1 object
12
- * @returns Chain-specific encoded data
13
- */
14
- abstract encodeMeta(meta: ProtocolMetaV1): any;
15
- /**
16
- * Decode protocol meta from chain-specific transaction
17
- * @param tx - Chain-specific transaction
18
- * @returns Decoded ProtocolMetaV1 or null
19
- */
20
- abstract decodeMeta(tx: T): ProtocolMetaV1 | null;
21
- /**
22
- * Inject protocol meta into chain-specific transaction
23
- * @param serializedTx - Serialized transaction string
24
- * @param meta - ProtocolMetaV1 object
25
- * @returns Serialized transaction with injected meta
26
- */
27
- abstract injectMeta(serializedTx: string, meta: ProtocolMetaV1): string;
28
- /**
29
- * Validate transaction with protocol meta and authority list
30
- * @param tx - Chain-specific transaction
31
- * @param authorities - Array of valid protocol authority identifiers
32
- * @param expectedPrefix - Expected protocol prefix (default: 'DEFAULT')
33
- * @returns True if transaction is valid
34
- */
35
- abstract validate(tx: T, authorities: string[], expectedPrefix?: string): boolean;
36
- /**
37
- * Check if the issuer has signed the transaction
38
- * @param tx - Chain-specific transaction
39
- * @param issuer - Issuer public key to check
40
- * @returns True if issuer has signed
41
- */
42
- abstract hasIssuerSignature(tx: T, issuer: string): boolean;
43
- /**
44
- * Detect tampered transactions by cross-checking metadata
45
- * @param tx - Chain-specific transaction
46
- * @param authorities - Array of valid protocol authority identifiers
47
- * @param expectedPrefix - Expected protocol prefix
48
- * @returns True if transaction is valid and not tampered
49
- */
50
- detectTampering(tx: T, authorities: string[], expectedPrefix?: string): boolean;
51
- /**
52
- * Chain-specific transaction integrity validation
53
- * Override this method for additional validation logic
54
- * @param tx - Chain-specific transaction
55
- * @param meta - Decoded protocol meta
56
- * @returns True if transaction integrity is valid
57
- */
58
- protected abstract validateTransactionIntegrity(tx: T, meta: ProtocolMetaV1): boolean;
59
- /**
60
- * Get the code signature message
61
- * @param code - The code to sign
62
- * @param timestamp - The timestamp of the code
63
- * @param prefix - The prefix of the code
64
- * @returns The code signature message
65
- */
66
- getCodeSignatureMessage(code: string, timestamp: number, prefix?: string): string;
67
- /**
68
- * Verify the code signature
69
- * This is specific to the chain and should be implemented by the concrete adapter
70
- * It will be used to verify the code signature for the action code if the right wallet is used to sign the code
71
- * @param actionCode - The action code to verify
72
- * @returns True if the code signature is valid
73
- */
74
- abstract verifyCodeSignature(actionCode: ActionCode): boolean;
75
- /**
76
- * Sign the transaction with the protocol key using a callback approach
77
- * This method should be implemented by each chain-specific adapter to handle
78
- * the chain's specific signing mechanism asynchronously
79
- * @param tx - Chain-specific transaction to sign
80
- * @param protocolPrivateKey - Private key or Keypair object depending on the chain
81
- * @param signCallback - Callback function that performs the actual signing
82
- * @returns Promise that resolves to the signed transaction
83
- */
84
- abstract signWithProtocolKey(actionCode: ActionCode, key: any): Promise<ActionCode>;
85
- /**
86
- * Verify the finalized transaction
87
- * @param tx - The finalized transaction to verify
88
- * @returns True if the transaction is valid
89
- */
90
- abstract verifyFinalizedTransaction(tx: any, actionCode: ActionCode): boolean;
91
- abstract validateSignedMessage(message: string, signedMessage: string, pubkey: string): boolean;
92
- }
93
- //# sourceMappingURL=base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/adapters/base.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC;;;GAGG;AACH,8BAAsB,gBAAgB,CAAC,CAAC,GAAG,GAAG;IAC1C,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEhC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,GAAG;IAE9C;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,cAAc,GAAG,IAAI;IAEjD;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,MAAM;IAEvE;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO;IAEjF;;;;;OAKG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAE3D;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,cAAc,GAAE,MAAkB,GAAG,OAAO;IA8B1F;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO;IAErF;;;;;;OAMG;IACH,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAE,MAA6B,GAAG,MAAM;IAIvG;;;;;;OAMG;IACH,QAAQ,CAAC,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;IAE7D;;;;;;;;OAQG;IACH,QAAQ,CAAC,mBAAmB,CACxB,UAAU,EAAE,UAAU,EACtB,GAAG,EAAE,GAAG,GACT,OAAO,CAAC,UAAU,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,CAAC,0BAA0B,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO;IAE7E,QAAQ,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;CAClG"}
@@ -1,65 +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.BaseChainAdapter = void 0;
17
- const constants_1 = require("../constants");
18
- /**
19
- * Base adapter class for chain-specific protocol meta operations
20
- * @template T - Chain-specific transaction type
21
- */
22
- class BaseChainAdapter {
23
- /**
24
- * Detect tampered transactions by cross-checking metadata
25
- * @param tx - Chain-specific transaction
26
- * @param authorities - Array of valid protocol authority identifiers
27
- * @param expectedPrefix - Expected protocol prefix
28
- * @returns True if transaction is valid and not tampered
29
- */
30
- detectTampering(tx, authorities, expectedPrefix = 'DEFAULT') {
31
- // First, decode the protocol meta from the transaction
32
- const meta = this.decodeMeta(tx);
33
- if (!meta) {
34
- return false; // No protocol meta found
35
- }
36
- // Validate the meta structure
37
- if (meta.version !== '1') {
38
- return false; // Invalid version
39
- }
40
- if (meta.prefix !== expectedPrefix) {
41
- return false; // Wrong prefix
42
- }
43
- // Check if issuer is in the authorities list
44
- if (!meta.iss || !authorities.includes(meta.iss)) {
45
- return false; // Invalid issuer
46
- }
47
- // Verify the issuer has actually signed the transaction
48
- if (!this.hasIssuerSignature(tx, meta.iss)) {
49
- return false; // Issuer didn't sign
50
- }
51
- // Additional chain-specific validation
52
- return this.validateTransactionIntegrity(tx, meta);
53
- }
54
- /**
55
- * Get the code signature message
56
- * @param code - The code to sign
57
- * @param timestamp - The timestamp of the code
58
- * @param prefix - The prefix of the code
59
- * @returns The code signature message
60
- */
61
- getCodeSignatureMessage(code, timestamp, prefix = constants_1.PROTOCOL_CODE_PREFIX) {
62
- return `${prefix}:${code}:${timestamp}`;
63
- }
64
- }
65
- exports.BaseChainAdapter = BaseChainAdapter;
@@ -1,2 +0,0 @@
1
- export * from './solana';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/solana/index.ts"],"names":[],"mappings":"AAcA,cAAc,UAAU,CAAC"}
@@ -1,30 +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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- var desc = Object.getOwnPropertyDescriptor(m, k);
18
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
- desc = { enumerable: true, get: function() { return m[k]; } };
20
- }
21
- Object.defineProperty(o, k2, desc);
22
- }) : (function(o, m, k, k2) {
23
- if (k2 === undefined) k2 = k;
24
- o[k2] = m[k];
25
- }));
26
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- __exportStar(require("./solana"), exports);
@@ -1,113 +0,0 @@
1
- import { Transaction, TransactionInstruction, VersionedTransaction, Keypair, VersionedTransactionResponse } from '@solana/web3.js';
2
- import { ProtocolMetaV1 } from '../../meta';
3
- import { BaseChainAdapter } from '../base';
4
- import { ActionCode } from '../../actioncode';
5
- /**
6
- * Solana transaction type union
7
- */
8
- export type SolanaTransaction = Transaction | VersionedTransaction;
9
- /**
10
- * Simple Solana adapter for protocol meta operations
11
- * Supports both legacy and versioned transactions
12
- */
13
- export declare class SolanaAdapter extends BaseChainAdapter<SolanaTransaction> {
14
- private static readonly MEMO_PROGRAM_ID;
15
- readonly chain = "solana";
16
- /**
17
- * Encode protocol meta as a Solana memo instruction
18
- * @param meta - The protocol meta to encode
19
- * @returns TransactionInstruction for the memo
20
- */
21
- encodeMeta(meta: ProtocolMetaV1): TransactionInstruction;
22
- /**
23
- * Decode protocol meta from Solana transaction (legacy or versioned)
24
- * @param tx - The Solana transaction (can be deserialized object or base64 string)
25
- * @returns Decoded ProtocolMetaV1 or null if not found
26
- */
27
- decodeMeta(tx: SolanaTransaction | string): ProtocolMetaV1 | null;
28
- /**
29
- * Deserialize a Solana transaction from base64 string
30
- * @param base64String - Base64 encoded transaction
31
- * @returns SolanaTransaction object
32
- */
33
- deserializeTransaction(base64String: string): SolanaTransaction;
34
- /**
35
- * Inject protocol meta into Solana transaction
36
- * @param serializedTx - Serialized transaction string (base64)
37
- * @param meta - ProtocolMetaV1 object
38
- * @returns Serialized transaction with injected meta
39
- */
40
- injectMeta(serializedTx: string, meta: ProtocolMetaV1): string;
41
- /**
42
- * Validate transaction with protocol meta and authority list
43
- * @param tx - The Solana transaction
44
- * @param authorities - Array of valid protocol authority public keys (base58)
45
- * @param expectedPrefix - Expected protocol prefix (default: 'DEFAULT')
46
- * @returns True if transaction is valid
47
- */
48
- validate(tx: SolanaTransaction, authorities: string[], expectedPrefix?: string): boolean;
49
- /**
50
- * Check if the issuer has signed the transaction
51
- * @param tx - The Solana transaction (can be deserialized object or base64 string)
52
- * @param issuer - Issuer public key to check
53
- * @returns True if issuer has signed
54
- */
55
- hasIssuerSignature(tx: SolanaTransaction | string, issuer: string): boolean;
56
- /**
57
- * Decode protocol meta from legacy Solana transaction
58
- */
59
- private decodeLegacyTransaction;
60
- /**
61
- * Decode protocol meta from versioned Solana transaction
62
- */
63
- private decodeVersionedTransaction;
64
- /**
65
- * Decode protocol meta from MessageV0
66
- */
67
- private decodeMessageV0;
68
- /**
69
- * Check if the issuer has signed a legacy transaction
70
- */
71
- private hasIssuerSignatureLegacy;
72
- /**
73
- * Check if the issuer has signed a versioned transaction
74
- */
75
- private hasIssuerSignatureVersioned;
76
- /**
77
- * Validate Solana transaction integrity with additional checks
78
- * @param tx - The Solana transaction
79
- * @param meta - Decoded protocol meta
80
- * @returns True if transaction integrity is valid
81
- */
82
- protected validateTransactionIntegrity(tx: SolanaTransaction, meta: ProtocolMetaV1): boolean;
83
- verifyCodeSignature(actionCode: ActionCode): boolean;
84
- /**
85
- * Decode protocol meta from base64 string (for backward compatibility)
86
- * @param base64String - Base64 encoded transaction
87
- * @returns Decoded ProtocolMetaV1 or null
88
- */
89
- decodeFromBase64(base64String: string): ProtocolMetaV1 | null;
90
- /**
91
- * Sign the transaction with the protocol key
92
- * @param actionCode - The action code containing the transaction
93
- * @param key - The keypair to sign with
94
- * @returns Promise that resolves to the signed action code
95
- */
96
- signWithProtocolKey(actionCode: ActionCode, key: Keypair): Promise<ActionCode>;
97
- /**
98
- * Verify the finalized transaction from blockchain
99
- * @param tx - The finalized transaction response from blockchain
100
- * @param actionCode - The action code to verify against
101
- * @returns True if the transaction is valid and matches the action code
102
- */
103
- verifyFinalizedTransaction(tx: VersionedTransactionResponse, actionCode: ActionCode): boolean;
104
- /**
105
- * Validate a signed message for sign-only mode
106
- * @param message - The message that was signed
107
- * @param signedMessage - The signed message (base64 or hex)
108
- * @param pubkey - The public key that should have signed the message
109
- * @returns True if the signature is valid
110
- */
111
- validateSignedMessage(message: string, signedMessage: string, pubkey: string): boolean;
112
- }
113
- //# sourceMappingURL=solana.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../../src/adapters/solana/solana.ts"],"names":[],"mappings":"AAcA,OAAO,EACH,WAAW,EACX,sBAAsB,EACtB,oBAAoB,EAGpB,OAAO,EACP,4BAA4B,EAC/B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,cAAc,EAAsB,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,oBAAoB,CAAC;AAEnE;;;GAGG;AACH,qBAAa,aAAc,SAAQ,gBAAgB,CAAC,iBAAiB,CAAC;IAClE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAmB;IAE1D,QAAQ,CAAC,KAAK,YAAY;IAE1B;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,sBAAsB;IAgBxD;;;;OAIG;IACH,UAAU,CAAC,EAAE,EAAE,iBAAiB,GAAG,MAAM,GAAG,cAAc,GAAG,IAAI;IAoBjE;;;;OAIG;IACI,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,iBAAiB;IActE;;;;;OAKG;IACH,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,MAAM;IA2E9D;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,cAAc,GAAE,MAAkB,GAAG,OAAO;IAInG;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,EAAE,iBAAiB,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAoB3E;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAUlC;;OAEG;IACH,OAAO,CAAC,eAAe;IAuBvB;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAMhC;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAenC;;;;;OAKG;IACH,SAAS,CAAC,4BAA4B,CAAC,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO;IA6BrF,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;IAa3D;;;;OAIG;IACH,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAI7D;;;;;OAKG;IACG,mBAAmB,CACrB,UAAU,EAAE,UAAU,EACtB,GAAG,EAAE,OAAO,GACb,OAAO,CAAC,UAAU,CAAC;IA4CtB;;;;;OAKG;IACH,0BAA0B,CAAC,EAAE,EAAE,4BAA4B,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO;IAwH7F;;;;;;OAMG;IACH,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;CAYzF"}