@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.
- package/LICENSE +2 -2
- package/README.md +32 -45
- package/dist/ActionCodesProtocol.d.ts +35 -0
- package/dist/ActionCodesProtocol.d.ts.map +1 -0
- package/dist/adapters/BaseChainAdapter.d.ts +22 -0
- package/dist/adapters/BaseChainAdapter.d.ts.map +1 -0
- package/dist/adapters/SolanaAdapter.d.ts +44 -0
- package/dist/adapters/SolanaAdapter.d.ts.map +1 -0
- package/dist/constants.d.ts +6 -8
- package/dist/constants.d.ts.map +1 -1
- package/dist/errors.d.ts +63 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +25 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -23
- package/dist/index.js.map +25 -0
- package/dist/strategy/DelegationStrategy.d.ts +43 -0
- package/dist/strategy/DelegationStrategy.d.ts.map +1 -0
- package/dist/strategy/WalletStrategy.d.ts +8 -0
- package/dist/strategy/WalletStrategy.d.ts.map +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/canonical.d.ts +5 -0
- package/dist/utils/canonical.d.ts.map +1 -0
- package/dist/utils/crypto.d.ts +13 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/protocolMeta.d.ts +16 -0
- package/dist/utils/protocolMeta.d.ts.map +1 -0
- package/docs/ActionCodesProtocol/README.md +11 -0
- package/docs/ActionCodesProtocol/classes/ActionCodesProtocol.md +147 -0
- package/docs/README.md +10 -50
- package/docs/adapters/BaseChainAdapter/README.md +20 -0
- package/docs/adapters/BaseChainAdapter/classes/BaseChainAdapter.md +56 -0
- package/docs/adapters/BaseChainAdapter/interfaces/BaseContext.md +17 -0
- package/docs/adapters/BaseChainAdapter/interfaces/ChainAdapter.md +33 -0
- package/docs/adapters/BaseChainAdapter/type-aliases/ChainContext.md +23 -0
- package/docs/adapters/NodeCryptoAdapter/README.md +15 -0
- package/docs/adapters/NodeCryptoAdapter/classes/NodeCryptoAdapter.md +254 -0
- package/docs/adapters/NodeCryptoAdapter/type-aliases/NodeCryptoContext.md +27 -0
- package/docs/adapters/SolanaAdapter/README.md +16 -0
- package/docs/adapters/SolanaAdapter/classes/SolanaAdapter.md +190 -0
- package/docs/adapters/SolanaAdapter/type-aliases/SolanaContext.md +27 -0
- package/docs/adapters/SolanaAdapter/type-aliases/SolanaTransaction.md +13 -0
- package/docs/constants/README.md +8 -13
- package/docs/constants/variables/CODE_CHARSET_DIGITS.md +11 -0
- package/docs/constants/variables/CODE_DEFAULT_LENGTH.md +11 -0
- package/docs/constants/variables/CODE_MAX_LENGTH.md +11 -0
- package/docs/constants/variables/CODE_MIN_LENGTH.md +11 -0
- package/docs/constants/variables/PROTOCOL_META_MAX_BYTES.md +11 -0
- package/docs/constants/variables/PROTOCOL_NORMALIZATION.md +11 -0
- package/docs/constants/variables/SUPPORTED_CHAINS.md +3 -3
- package/docs/errors/README.md +22 -0
- package/docs/errors/classes/ExpiredCodeError.md +695 -0
- package/docs/errors/classes/InvalidCodeFormatError.md +691 -0
- package/docs/errors/classes/InvalidPubkeyFormatError.md +691 -0
- package/docs/errors/classes/InvalidSignatureError.md +687 -0
- package/docs/errors/classes/MetaMismatchError.md +695 -0
- package/docs/errors/classes/MissingMetaError.md +681 -0
- package/docs/errors/classes/ProtocolError.md +637 -0
- package/docs/errors/classes/TransactionNotSignedByIntendedOwnerError.md +691 -0
- package/docs/errors/enumerations/ProtocolErrorCode.md +121 -0
- package/docs/index/README.md +83 -41
- package/docs/modules.md +12 -9
- package/docs/strategy/WalletStrategy/README.md +11 -0
- package/docs/strategy/WalletStrategy/classes/WalletStrategy.md +67 -0
- package/docs/types/README.md +14 -0
- package/docs/types/interfaces/ActionCode.md +65 -0
- package/docs/types/interfaces/CanonicalMessageParts.md +33 -0
- package/docs/types/interfaces/CodeGenerationConfig.md +33 -0
- package/docs/types/interfaces/CodeGenerationResult.md +25 -0
- package/docs/utils/canonical/README.md +16 -0
- package/docs/utils/canonical/functions/serializeCanonical.md +21 -0
- package/docs/utils/canonical/variables/CANONICAL_MESSAGE_PREFIX.md +11 -0
- package/docs/utils/canonical/variables/CANONICAL_MESSAGE_VERSION.md +11 -0
- package/docs/utils/crypto/README.md +18 -0
- package/docs/utils/crypto/functions/base32EncodeCrockford.md +21 -0
- package/docs/utils/crypto/functions/codeHash.md +21 -0
- package/docs/utils/crypto/functions/digestToDigits.md +25 -0
- package/docs/utils/crypto/functions/generateRandomSecret.md +15 -0
- package/docs/utils/crypto/functions/hkdfSha256.md +35 -0
- package/docs/utils/crypto/functions/hmacSha256.md +25 -0
- package/docs/utils/crypto/functions/sha256.md +21 -0
- package/docs/utils/crypto/functions/truncateBits.md +25 -0
- package/docs/utils/protocolMeta/README.md +21 -0
- package/docs/utils/protocolMeta/functions/buildProtocolMeta.md +21 -0
- package/docs/utils/protocolMeta/functions/parseProtocolMeta.md +21 -0
- package/docs/utils/protocolMeta/functions/validateProtocolMetaFormat.md +21 -0
- package/docs/utils/protocolMeta/interfaces/ProtocolMetaFields.md +41 -0
- package/docs/utils/protocolMeta/variables/SCHEME.md +11 -0
- package/package.json +42 -47
- package/dist/actioncode.d.ts +0 -120
- package/dist/actioncode.d.ts.map +0 -1
- package/dist/actioncode.js +0 -173
- package/dist/adapters/base.d.ts +0 -93
- package/dist/adapters/base.d.ts.map +0 -1
- package/dist/adapters/base.js +0 -52
- package/dist/adapters/solana/index.d.ts +0 -2
- package/dist/adapters/solana/index.d.ts.map +0 -1
- package/dist/adapters/solana/index.js +0 -17
- package/dist/adapters/solana/solana.d.ts +0 -113
- package/dist/adapters/solana/solana.d.ts.map +0 -1
- package/dist/adapters/solana/solana.js +0 -524
- package/dist/codegen.d.ts +0 -76
- package/dist/codegen.d.ts.map +0 -1
- package/dist/codegen.js +0 -198
- package/dist/constants.js +0 -11
- package/dist/meta.d.ts +0 -54
- package/dist/meta.d.ts.map +0 -1
- package/dist/meta.js +0 -91
- package/dist/protocol.d.ts +0 -179
- package/dist/protocol.d.ts.map +0 -1
- package/dist/protocol.js +0 -377
- package/docs/_media/LICENSE +0 -201
- package/docs/_media/README.md +0 -28
- package/docs/actioncode/README.md +0 -21
- package/docs/actioncode/classes/ActionCode.md +0 -430
- package/docs/actioncode/interfaces/ActionCodeFields.md +0 -89
- package/docs/actioncode/interfaces/ActionCodeMetadata.md +0 -25
- package/docs/actioncode/interfaces/ActionCodeTransaction.md +0 -57
- package/docs/actioncode/type-aliases/ActionCodeStatus.md +0 -11
- package/docs/adapters/base/README.md +0 -11
- package/docs/adapters/base/classes/BaseChainAdapter.md +0 -396
- package/docs/adapters/solana/README.md +0 -19
- package/docs/adapters/solana/solana/README.md +0 -15
- package/docs/adapters/solana/solana/classes/SolanaAdapter.md +0 -506
- package/docs/adapters/solana/solana/type-aliases/SolanaTransaction.md +0 -13
- package/docs/codegen/README.md +0 -11
- package/docs/codegen/classes/CodeGenerator.md +0 -341
- package/docs/constants/type-aliases/SupportedChain.md +0 -11
- package/docs/constants/variables/CODE_LENGTH.md +0 -11
- package/docs/constants/variables/CODE_TTL.md +0 -11
- package/docs/constants/variables/MAX_PREFIX_LENGTH.md +0 -11
- package/docs/constants/variables/MIN_PREFIX_LENGTH.md +0 -11
- package/docs/constants/variables/PROTOCOL_CODE_PREFIX.md +0 -11
- package/docs/constants/variables/PROTOCOL_PREFIX.md +0 -11
- package/docs/constants/variables/PROTOCOL_VERSION.md +0 -11
- package/docs/meta/README.md +0 -15
- package/docs/meta/classes/ProtocolMetaParser.md +0 -177
- package/docs/meta/interfaces/ProtocolMetaV1.md +0 -59
- package/docs/protocol/README.md +0 -51
- package/docs/protocol/classes/ActionCodesProtocol.md +0 -676
- package/docs/protocol/interfaces/ProtocolConfig.md +0 -71
package/dist/actioncode.js
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ActionCode = void 0;
|
4
|
-
const codegen_1 = require("./codegen");
|
5
|
-
const buffer_1 = require("buffer");
|
6
|
-
class ActionCode {
|
7
|
-
constructor(fields) {
|
8
|
-
this.fields = fields;
|
9
|
-
}
|
10
|
-
static fromPayload(input) {
|
11
|
-
if (!input.code || !input.pubkey || !input.signature || !input.timestamp || !input.expiresAt || !input.chain || !input.status) {
|
12
|
-
throw new Error("Missing required fields in ActionCode payload");
|
13
|
-
}
|
14
|
-
return new ActionCode(input);
|
15
|
-
}
|
16
|
-
static fromEncoded(encoded) {
|
17
|
-
const decoded = JSON.parse(buffer_1.Buffer.from(encoded, 'base64').toString('utf8'));
|
18
|
-
return ActionCode.fromPayload(decoded);
|
19
|
-
}
|
20
|
-
get encoded() {
|
21
|
-
return buffer_1.Buffer.from(JSON.stringify(this.fields), 'utf8').toString('base64');
|
22
|
-
}
|
23
|
-
isValid(protocol) {
|
24
|
-
if (this.expired)
|
25
|
-
return false;
|
26
|
-
const adapter = protocol.getChainAdapter(this.chain);
|
27
|
-
if (!adapter)
|
28
|
-
throw new Error(`Chain adapter not found for chain ${this.chain}`);
|
29
|
-
const isSignatureValid = adapter.verifyCodeSignature(this);
|
30
|
-
const isCodeValid = codegen_1.CodeGenerator.validateCode(this.fields.code, this.fields.pubkey, this.fields.timestamp, this.fields.prefix);
|
31
|
-
return isSignatureValid && isCodeValid;
|
32
|
-
}
|
33
|
-
updateStatus(status) {
|
34
|
-
this.fields.status = status;
|
35
|
-
}
|
36
|
-
get json() {
|
37
|
-
return this.fields;
|
38
|
-
}
|
39
|
-
// UX-focused helper methods
|
40
|
-
/**
|
41
|
-
* Get remaining time in milliseconds until expiration
|
42
|
-
* @returns Remaining time in milliseconds, or 0 if expired
|
43
|
-
*/
|
44
|
-
get remainingTime() {
|
45
|
-
const now = Date.now();
|
46
|
-
return Math.max(0, this.fields.expiresAt - now); // TODO: rename to remainingTime
|
47
|
-
}
|
48
|
-
/**
|
49
|
-
* Check if the action code has expired
|
50
|
-
* @returns True if the code has expired
|
51
|
-
*/
|
52
|
-
get expired() {
|
53
|
-
return this.remainingTime === 0; // TODO: rename to expired
|
54
|
-
}
|
55
|
-
/**
|
56
|
-
* Get the target chain for this action code
|
57
|
-
* @returns Chain identifier (e.g., "solana", "evm")
|
58
|
-
*/
|
59
|
-
get chain() {
|
60
|
-
return this.fields.chain;
|
61
|
-
}
|
62
|
-
/**
|
63
|
-
* Get the current status of the action code
|
64
|
-
* @returns Current status
|
65
|
-
*/
|
66
|
-
get status() {
|
67
|
-
return this.fields.status;
|
68
|
-
}
|
69
|
-
/**
|
70
|
-
* Get the action code string
|
71
|
-
* @returns The 8-character action code
|
72
|
-
*/
|
73
|
-
get code() {
|
74
|
-
return this.fields.code;
|
75
|
-
}
|
76
|
-
/**
|
77
|
-
* Get the prefix used for this action code
|
78
|
-
* @returns Normalized prefix
|
79
|
-
*/
|
80
|
-
get prefix() {
|
81
|
-
return this.fields.prefix;
|
82
|
-
}
|
83
|
-
/**
|
84
|
-
* Get the user's public key
|
85
|
-
* @returns User's public key
|
86
|
-
*/
|
87
|
-
get pubkey() {
|
88
|
-
return this.fields.pubkey;
|
89
|
-
}
|
90
|
-
/**
|
91
|
-
* Get the transaction data (chain-specific)
|
92
|
-
* @returns Transaction data or undefined
|
93
|
-
*/
|
94
|
-
get transaction() {
|
95
|
-
return this.fields.transaction;
|
96
|
-
}
|
97
|
-
/**
|
98
|
-
* Get metadata associated with this action code
|
99
|
-
* @returns Metadata object or undefined
|
100
|
-
*/
|
101
|
-
get metadata() {
|
102
|
-
return this.fields.metadata;
|
103
|
-
}
|
104
|
-
/**
|
105
|
-
* Get a human-readable description of the action
|
106
|
-
* @returns Description string or undefined
|
107
|
-
*/
|
108
|
-
get description() {
|
109
|
-
return this.fields.metadata?.description;
|
110
|
-
}
|
111
|
-
/**
|
112
|
-
* Get parameters associated with this action
|
113
|
-
* @returns Parameters object or undefined
|
114
|
-
*/
|
115
|
-
get params() {
|
116
|
-
return this.fields.metadata?.params;
|
117
|
-
}
|
118
|
-
/**
|
119
|
-
* Get the timestamp when the code was generated
|
120
|
-
* @returns Timestamp in milliseconds
|
121
|
-
*/
|
122
|
-
get timestamp() {
|
123
|
-
return this.fields.timestamp;
|
124
|
-
}
|
125
|
-
/**
|
126
|
-
* Get the user's signature
|
127
|
-
* @returns User's signature string
|
128
|
-
*/
|
129
|
-
get signature() {
|
130
|
-
return this.fields.signature;
|
131
|
-
}
|
132
|
-
/**
|
133
|
-
* Get a human-readable display string for the action code
|
134
|
-
* @returns Formatted display string
|
135
|
-
*/
|
136
|
-
get displayString() {
|
137
|
-
const prefix = this.fields.prefix === 'DEFAULT' ? '' : `${this.fields.prefix}-`;
|
138
|
-
const code = this.fields.code;
|
139
|
-
const chain = this.fields.chain;
|
140
|
-
const status = this.fields.status;
|
141
|
-
return `${prefix}${code} (${chain}, ${status})`;
|
142
|
-
}
|
143
|
-
/**
|
144
|
-
* Get a formatted time string showing remaining time
|
145
|
-
* @returns Human-readable time string (e.g., "1m 30s remaining")
|
146
|
-
*/
|
147
|
-
get remainingTimeString() {
|
148
|
-
const remaining = this.remainingTime;
|
149
|
-
if (remaining === 0) {
|
150
|
-
return 'Expired';
|
151
|
-
}
|
152
|
-
const minutes = Math.floor(remaining / 60000);
|
153
|
-
const seconds = Math.floor((remaining % 60000) / 1000);
|
154
|
-
if (minutes > 0) {
|
155
|
-
return `${minutes}m ${seconds}s remaining`;
|
156
|
-
}
|
157
|
-
else {
|
158
|
-
return `${seconds}s remaining`;
|
159
|
-
}
|
160
|
-
}
|
161
|
-
/**
|
162
|
-
* Get the code hash for this action code
|
163
|
-
* it is also used in the protocol meta as the code id
|
164
|
-
* @returns Code hash string
|
165
|
-
*/
|
166
|
-
get codeHash() {
|
167
|
-
return codegen_1.CodeGenerator.deriveCodeHash(this.fields.pubkey, this.fields.prefix, this.fields.timestamp);
|
168
|
-
}
|
169
|
-
get intentType() {
|
170
|
-
return this.fields.transaction?.intentType || 'transaction';
|
171
|
-
}
|
172
|
-
}
|
173
|
-
exports.ActionCode = ActionCode;
|
package/dist/adapters/base.d.ts
DELETED
@@ -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":"AAAA,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"}
|
package/dist/adapters/base.js
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.BaseChainAdapter = void 0;
|
4
|
-
const constants_1 = require("../constants");
|
5
|
-
/**
|
6
|
-
* Base adapter class for chain-specific protocol meta operations
|
7
|
-
* @template T - Chain-specific transaction type
|
8
|
-
*/
|
9
|
-
class BaseChainAdapter {
|
10
|
-
/**
|
11
|
-
* Detect tampered transactions by cross-checking metadata
|
12
|
-
* @param tx - Chain-specific transaction
|
13
|
-
* @param authorities - Array of valid protocol authority identifiers
|
14
|
-
* @param expectedPrefix - Expected protocol prefix
|
15
|
-
* @returns True if transaction is valid and not tampered
|
16
|
-
*/
|
17
|
-
detectTampering(tx, authorities, expectedPrefix = 'DEFAULT') {
|
18
|
-
// First, decode the protocol meta from the transaction
|
19
|
-
const meta = this.decodeMeta(tx);
|
20
|
-
if (!meta) {
|
21
|
-
return false; // No protocol meta found
|
22
|
-
}
|
23
|
-
// Validate the meta structure
|
24
|
-
if (meta.version !== '1') {
|
25
|
-
return false; // Invalid version
|
26
|
-
}
|
27
|
-
if (meta.prefix !== expectedPrefix) {
|
28
|
-
return false; // Wrong prefix
|
29
|
-
}
|
30
|
-
// Check if issuer is in the authorities list
|
31
|
-
if (!meta.iss || !authorities.includes(meta.iss)) {
|
32
|
-
return false; // Invalid issuer
|
33
|
-
}
|
34
|
-
// Verify the issuer has actually signed the transaction
|
35
|
-
if (!this.hasIssuerSignature(tx, meta.iss)) {
|
36
|
-
return false; // Issuer didn't sign
|
37
|
-
}
|
38
|
-
// Additional chain-specific validation
|
39
|
-
return this.validateTransactionIntegrity(tx, meta);
|
40
|
-
}
|
41
|
-
/**
|
42
|
-
* Get the code signature message
|
43
|
-
* @param code - The code to sign
|
44
|
-
* @param timestamp - The timestamp of the code
|
45
|
-
* @param prefix - The prefix of the code
|
46
|
-
* @returns The code signature message
|
47
|
-
*/
|
48
|
-
getCodeSignatureMessage(code, timestamp, prefix = constants_1.PROTOCOL_CODE_PREFIX) {
|
49
|
-
return `${prefix}:${code}:${timestamp}`;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
exports.BaseChainAdapter = BaseChainAdapter;
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/solana/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./solana"), exports);
|
@@ -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":"AAAA,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"}
|