@actioncodes/protocol 1.0.3 → 1.1.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.
- package/dist/adapters/base.d.ts +19 -2
- package/dist/adapters/base.d.ts.map +1 -1
- package/dist/adapters/base.js +1 -1
- package/dist/adapters/solana/solana.d.ts +16 -3
- package/dist/adapters/solana/solana.d.ts.map +1 -1
- package/dist/adapters/solana/solana.js +107 -14
- package/dist/protocol.js +3 -3
- package/docs/actioncode/classes/ActionCode.md +23 -23
- package/docs/actioncode/interfaces/ActionCodeFields.md +11 -11
- package/docs/actioncode/interfaces/ActionCodeMetadata.md +3 -3
- package/docs/actioncode/interfaces/ActionCodeTransaction.md +4 -4
- package/docs/actioncode/type-aliases/ActionCodeStatus.md +1 -1
- package/docs/adapters/base/classes/BaseChainAdapter.md +72 -14
- package/docs/adapters/solana/solana/classes/SolanaAdapter.md +97 -33
- package/docs/adapters/solana/solana/type-aliases/SolanaTransaction.md +1 -1
- package/docs/codegen/classes/CodeGenerator.md +14 -14
- package/docs/constants/type-aliases/SupportedChain.md +1 -1
- package/docs/constants/variables/CODE_LENGTH.md +1 -1
- package/docs/constants/variables/CODE_TTL.md +1 -1
- package/docs/constants/variables/MAX_PREFIX_LENGTH.md +1 -1
- package/docs/constants/variables/MIN_PREFIX_LENGTH.md +1 -1
- package/docs/constants/variables/PROTOCOL_CODE_PREFIX.md +1 -1
- package/docs/constants/variables/PROTOCOL_PREFIX.md +1 -1
- package/docs/constants/variables/PROTOCOL_VERSION.md +1 -1
- package/docs/constants/variables/SUPPORTED_CHAINS.md +1 -1
- package/docs/meta/classes/ProtocolMetaParser.md +6 -6
- package/docs/meta/interfaces/ProtocolMetaV1.md +7 -7
- package/docs/protocol/classes/ActionCodesProtocol.md +21 -21
- package/docs/protocol/interfaces/ProtocolConfig.md +7 -7
- package/package.json +1 -1
package/dist/adapters/base.d.ts
CHANGED
@@ -11,13 +11,20 @@ export declare abstract class BaseChainAdapter<T = any> {
|
|
11
11
|
* @param meta - ProtocolMetaV1 object
|
12
12
|
* @returns Chain-specific encoded data
|
13
13
|
*/
|
14
|
-
abstract
|
14
|
+
abstract encodeMeta(meta: ProtocolMetaV1): any;
|
15
15
|
/**
|
16
16
|
* Decode protocol meta from chain-specific transaction
|
17
17
|
* @param tx - Chain-specific transaction
|
18
18
|
* @returns Decoded ProtocolMetaV1 or null
|
19
19
|
*/
|
20
|
-
abstract
|
20
|
+
abstract decodeMeta(tx: T): ProtocolMetaV1 | null;
|
21
|
+
/**
|
22
|
+
* Inject protocol meta into chain-specific transaction
|
23
|
+
* @param tx - Chain-specific transaction
|
24
|
+
* @param meta - ProtocolMetaV1 object
|
25
|
+
* @returns Chain-specific transaction with injected meta
|
26
|
+
*/
|
27
|
+
abstract injectMeta(tx: T, meta: ProtocolMetaV1): T;
|
21
28
|
/**
|
22
29
|
* Validate transaction with protocol meta and authority list
|
23
30
|
* @param tx - Chain-specific transaction
|
@@ -65,5 +72,15 @@ export declare abstract class BaseChainAdapter<T = any> {
|
|
65
72
|
* @returns True if the code signature is valid
|
66
73
|
*/
|
67
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>;
|
68
85
|
}
|
69
86
|
//# sourceMappingURL=base.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/adapters/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAA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AE,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;CACzB"}
|
package/dist/adapters/base.js
CHANGED
@@ -16,7 +16,7 @@ class BaseChainAdapter {
|
|
16
16
|
*/
|
17
17
|
detectTampering(tx, authorities, expectedPrefix = 'DEFAULT') {
|
18
18
|
// First, decode the protocol meta from the transaction
|
19
|
-
const meta = this.
|
19
|
+
const meta = this.decodeMeta(tx);
|
20
20
|
if (!meta) {
|
21
21
|
return false; // No protocol meta found
|
22
22
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
1
|
+
import { Transaction, TransactionInstruction, VersionedTransaction, Keypair } from '@solana/web3.js';
|
2
2
|
import { ProtocolMetaV1 } from '../../meta';
|
3
3
|
import { BaseChainAdapter } from '../base';
|
4
4
|
import { ActionCode } from '../../actioncode';
|
@@ -18,13 +18,20 @@ export declare class SolanaAdapter extends BaseChainAdapter<SolanaTransaction> {
|
|
18
18
|
* @param meta - The protocol meta to encode
|
19
19
|
* @returns TransactionInstruction for the memo
|
20
20
|
*/
|
21
|
-
|
21
|
+
encodeMeta(meta: ProtocolMetaV1): TransactionInstruction;
|
22
22
|
/**
|
23
23
|
* Decode protocol meta from Solana transaction (legacy or versioned)
|
24
24
|
* @param tx - The Solana transaction
|
25
25
|
* @returns Decoded ProtocolMetaV1 or null if not found
|
26
26
|
*/
|
27
|
-
|
27
|
+
decodeMeta(tx: SolanaTransaction): ProtocolMetaV1 | null;
|
28
|
+
/**
|
29
|
+
* Inject protocol meta into Solana transaction
|
30
|
+
* @param tx - The Solana transaction
|
31
|
+
* @param meta - ProtocolMetaV1 object
|
32
|
+
* @returns Solana transaction with injected meta
|
33
|
+
*/
|
34
|
+
injectMeta(tx: SolanaTransaction, meta: ProtocolMetaV1): SolanaTransaction;
|
28
35
|
/**
|
29
36
|
* Validate transaction with protocol meta and authority list
|
30
37
|
* @param tx - The Solana transaction
|
@@ -82,5 +89,11 @@ export declare class SolanaAdapter extends BaseChainAdapter<SolanaTransaction> {
|
|
82
89
|
*/
|
83
90
|
validateFromBase64(base64String: string, authorities: string[], expectedPrefix?: string): boolean;
|
84
91
|
verifyCodeSignature(actionCode: ActionCode): boolean;
|
92
|
+
/**
|
93
|
+
* Sign the transaction with the protocol key using a callback approach
|
94
|
+
* @param signCallback - Callback function that performs the actual signing
|
95
|
+
* @returns Promise that resolves to the signed transaction
|
96
|
+
*/
|
97
|
+
signWithProtocolKey(actionCode: ActionCode, key: Keypair): Promise<ActionCode>;
|
85
98
|
}
|
86
99
|
//# sourceMappingURL=solana.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../../src/adapters/solana/solana.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,sBAAsB,EACtB,oBAAoB,
|
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,EACV,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;AAG9C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GA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AAmB,CACrB,UAAU,EAAE,UAAU,EACtB,GAAG,EAAE,OAAO,GACb,OAAO,CAAC,UAAU,CAAC;CAkCzB"}
|
@@ -54,16 +54,26 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
54
54
|
* @param meta - The protocol meta to encode
|
55
55
|
* @returns TransactionInstruction for the memo
|
56
56
|
*/
|
57
|
-
|
57
|
+
encodeMeta(meta) {
|
58
58
|
const metaString = meta_1.ProtocolMetaParser.serialize(meta);
|
59
|
-
|
59
|
+
const signerPubkeys = [];
|
60
|
+
try {
|
61
|
+
if (meta.iss && meta.iss !== 'undefined') {
|
62
|
+
const pubkey = new web3_js_1.PublicKey(meta.iss);
|
63
|
+
signerPubkeys.push(pubkey);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
catch (error) {
|
67
|
+
// Ignore error, issuer is not a valid public key
|
68
|
+
}
|
69
|
+
return (0, spl_memo_1.createMemoInstruction)(metaString, signerPubkeys);
|
60
70
|
}
|
61
71
|
/**
|
62
72
|
* Decode protocol meta from Solana transaction (legacy or versioned)
|
63
73
|
* @param tx - The Solana transaction
|
64
74
|
* @returns Decoded ProtocolMetaV1 or null if not found
|
65
75
|
*/
|
66
|
-
|
76
|
+
decodeMeta(tx) {
|
67
77
|
// Check if it's a versioned transaction
|
68
78
|
if ('message' in tx && tx.message) {
|
69
79
|
return this.decodeVersionedTransaction(tx);
|
@@ -75,6 +85,50 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
75
85
|
return null;
|
76
86
|
}
|
77
87
|
}
|
88
|
+
/**
|
89
|
+
* Inject protocol meta into Solana transaction
|
90
|
+
* @param tx - The Solana transaction
|
91
|
+
* @param meta - ProtocolMetaV1 object
|
92
|
+
* @returns Solana transaction with injected meta
|
93
|
+
*/
|
94
|
+
injectMeta(tx, meta) {
|
95
|
+
const metaIx = this.encodeMeta(meta);
|
96
|
+
if (tx instanceof web3_js_1.VersionedTransaction) {
|
97
|
+
// Convert TransactionInstruction to MessageCompiledInstruction for versioned transactions
|
98
|
+
// First, ensure all required keys are in static account keys
|
99
|
+
metaIx.keys.forEach(({ pubkey }) => {
|
100
|
+
if (!tx.message.staticAccountKeys.some(key => key.equals(pubkey))) {
|
101
|
+
tx.message.staticAccountKeys.push(pubkey);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
// Ensure programId is also in static keys
|
105
|
+
if (!tx.message.staticAccountKeys.some(key => key.equals(metaIx.programId))) {
|
106
|
+
tx.message.staticAccountKeys.push(metaIx.programId);
|
107
|
+
}
|
108
|
+
// Now find the program ID index after ensuring it's in the static keys
|
109
|
+
const programIdIndex = tx.message.staticAccountKeys.findIndex(key => key.equals(metaIx.programId));
|
110
|
+
const accountKeyIndexes = metaIx.keys.map(key => {
|
111
|
+
const index = tx.message.staticAccountKeys.findIndex(staticKey => staticKey.equals(key.pubkey));
|
112
|
+
if (index === -1) {
|
113
|
+
throw new Error(`Account key ${key.pubkey.toBase58()} not found in static account keys`);
|
114
|
+
}
|
115
|
+
return index;
|
116
|
+
});
|
117
|
+
const compiledInstruction = {
|
118
|
+
programIdIndex,
|
119
|
+
accountKeyIndexes,
|
120
|
+
data: metaIx.data
|
121
|
+
};
|
122
|
+
tx.message.compiledInstructions.push(compiledInstruction);
|
123
|
+
}
|
124
|
+
else if (tx instanceof web3_js_1.Transaction) {
|
125
|
+
tx.instructions.push(metaIx);
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
throw new Error('Invalid transaction type');
|
129
|
+
}
|
130
|
+
return tx;
|
131
|
+
}
|
78
132
|
/**
|
79
133
|
* Validate transaction with protocol meta and authority list
|
80
134
|
* @param tx - The Solana transaction
|
@@ -114,13 +168,13 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
114
168
|
try {
|
115
169
|
const memoString = new TextDecoder().decode(memoData);
|
116
170
|
const meta = meta_1.ProtocolMetaParser.parse(memoString);
|
117
|
-
if (meta && meta.version
|
118
|
-
return
|
171
|
+
if (meta && meta.version === '1') {
|
172
|
+
return meta;
|
119
173
|
}
|
120
|
-
|
174
|
+
// Continue searching if this memo is not a valid protocol meta
|
121
175
|
}
|
122
176
|
catch {
|
123
|
-
|
177
|
+
// Continue searching if this memo cannot be parsed
|
124
178
|
}
|
125
179
|
}
|
126
180
|
}
|
@@ -151,13 +205,13 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
151
205
|
try {
|
152
206
|
const memoString = new TextDecoder().decode(memoData);
|
153
207
|
const meta = meta_1.ProtocolMetaParser.parse(memoString);
|
154
|
-
if (meta && meta.version
|
155
|
-
return
|
208
|
+
if (meta && meta.version === '1') {
|
209
|
+
return meta;
|
156
210
|
}
|
157
|
-
|
211
|
+
// Continue searching if this memo is not a valid protocol meta
|
158
212
|
}
|
159
213
|
catch {
|
160
|
-
|
214
|
+
// Continue searching if this memo cannot be parsed
|
161
215
|
}
|
162
216
|
}
|
163
217
|
}
|
@@ -195,10 +249,16 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
195
249
|
// Additional Solana-specific validation can be added here
|
196
250
|
// For example, checking transaction signatures, recent blockhash, etc.
|
197
251
|
// Verify that the memo instruction contains the expected protocol meta
|
198
|
-
const decodedMeta = this.
|
252
|
+
const decodedMeta = this.decodeMeta(tx);
|
199
253
|
if (!decodedMeta) {
|
200
254
|
return false;
|
201
255
|
}
|
256
|
+
if (!meta.iss) {
|
257
|
+
return false;
|
258
|
+
}
|
259
|
+
if (!this.hasIssuerSignature(tx, meta.iss)) {
|
260
|
+
return false;
|
261
|
+
}
|
202
262
|
// Cross-check the decoded meta with the provided meta
|
203
263
|
return (decodedMeta.version === meta.version &&
|
204
264
|
decodedMeta.prefix === meta.prefix &&
|
@@ -218,11 +278,11 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
218
278
|
// Try legacy first, then versioned
|
219
279
|
try {
|
220
280
|
const transaction = web3_js_1.Transaction.from(buffer);
|
221
|
-
return this.
|
281
|
+
return this.decodeMeta(transaction);
|
222
282
|
}
|
223
283
|
catch {
|
224
284
|
const transaction = web3_js_1.VersionedTransaction.deserialize(buffer);
|
225
|
-
return this.
|
285
|
+
return this.decodeMeta(transaction);
|
226
286
|
}
|
227
287
|
}
|
228
288
|
catch {
|
@@ -265,6 +325,39 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
265
325
|
return false;
|
266
326
|
}
|
267
327
|
}
|
328
|
+
/**
|
329
|
+
* Sign the transaction with the protocol key using a callback approach
|
330
|
+
* @param signCallback - Callback function that performs the actual signing
|
331
|
+
* @returns Promise that resolves to the signed transaction
|
332
|
+
*/
|
333
|
+
async signWithProtocolKey(actionCode, key) {
|
334
|
+
try {
|
335
|
+
if (!actionCode.transaction?.transaction) {
|
336
|
+
throw new Error('No transaction found');
|
337
|
+
}
|
338
|
+
const tx = web3_js_1.Transaction.from(buffer_1.Buffer.from(actionCode.transaction.transaction, 'base64'));
|
339
|
+
tx.partialSign(key);
|
340
|
+
const meta = this.decodeMeta(tx);
|
341
|
+
if (!meta) {
|
342
|
+
throw new Error('Invalid transaction, protocol meta not found');
|
343
|
+
}
|
344
|
+
if (!this.validateTransactionIntegrity(tx, meta)) {
|
345
|
+
throw new Error('Invalid transaction, transaction integrity not valid');
|
346
|
+
}
|
347
|
+
const newActionCode = Object.assign({}, actionCode, {
|
348
|
+
transaction: {
|
349
|
+
...actionCode.transaction,
|
350
|
+
transaction: buffer_1.Buffer.from(tx.serialize({
|
351
|
+
requireAllSignatures: false
|
352
|
+
})).toString('base64'),
|
353
|
+
}
|
354
|
+
});
|
355
|
+
return newActionCode;
|
356
|
+
}
|
357
|
+
catch (error) {
|
358
|
+
throw new Error(`Failed to sign transaction with protocol key: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
359
|
+
}
|
360
|
+
}
|
268
361
|
}
|
269
362
|
exports.SolanaAdapter = SolanaAdapter;
|
270
363
|
SolanaAdapter.MEMO_PROGRAM_ID = spl_memo_1.MEMO_PROGRAM_ID;
|
package/dist/protocol.js
CHANGED
@@ -180,7 +180,7 @@ class ActionCodesProtocol {
|
|
180
180
|
if (!adapter) {
|
181
181
|
throw new Error(`Chain '${chain}' is not supported`);
|
182
182
|
}
|
183
|
-
return adapter.
|
183
|
+
return adapter.encodeMeta(meta);
|
184
184
|
}
|
185
185
|
/**
|
186
186
|
* Decode protocol meta from a transaction
|
@@ -193,7 +193,7 @@ class ActionCodesProtocol {
|
|
193
193
|
if (!adapter) {
|
194
194
|
return null;
|
195
195
|
}
|
196
|
-
return adapter.
|
196
|
+
return adapter.decodeMeta(transaction);
|
197
197
|
}
|
198
198
|
/**
|
199
199
|
* Validate a transaction with protocol meta
|
@@ -251,7 +251,7 @@ class ActionCodesProtocol {
|
|
251
251
|
if (!adapter) {
|
252
252
|
return null;
|
253
253
|
}
|
254
|
-
return adapter.
|
254
|
+
return adapter.decodeMeta(transaction);
|
255
255
|
}
|
256
256
|
/**
|
257
257
|
* Get protocol configuration
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
# Class: ActionCode
|
8
8
|
|
9
|
-
Defined in: [actioncode.ts:32](https://github.com/otaprotocol/actioncodes/blob/
|
9
|
+
Defined in: [actioncode.ts:32](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L32)
|
10
10
|
|
11
11
|
## Constructors
|
12
12
|
|
@@ -14,7 +14,7 @@ Defined in: [actioncode.ts:32](https://github.com/otaprotocol/actioncodes/blob/0
|
|
14
14
|
|
15
15
|
> **new ActionCode**(`fields`): `ActionCode`
|
16
16
|
|
17
|
-
Defined in: [actioncode.ts:33](https://github.com/otaprotocol/actioncodes/blob/
|
17
|
+
Defined in: [actioncode.ts:33](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L33)
|
18
18
|
|
19
19
|
#### Parameters
|
20
20
|
|
@@ -34,7 +34,7 @@ Defined in: [actioncode.ts:33](https://github.com/otaprotocol/actioncodes/blob/0
|
|
34
34
|
|
35
35
|
> **get** **chain**(): `string`
|
36
36
|
|
37
|
-
Defined in: [actioncode.ts:95](https://github.com/otaprotocol/actioncodes/blob/
|
37
|
+
Defined in: [actioncode.ts:95](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L95)
|
38
38
|
|
39
39
|
Get the target chain for this action code
|
40
40
|
|
@@ -52,7 +52,7 @@ Chain identifier (e.g., "solana", "evm")
|
|
52
52
|
|
53
53
|
> **get** **code**(): `string`
|
54
54
|
|
55
|
-
Defined in: [actioncode.ts:111](https://github.com/otaprotocol/actioncodes/blob/
|
55
|
+
Defined in: [actioncode.ts:111](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L111)
|
56
56
|
|
57
57
|
Get the action code string
|
58
58
|
|
@@ -70,7 +70,7 @@ The 8-character action code
|
|
70
70
|
|
71
71
|
> **get** **codeHash**(): `string`
|
72
72
|
|
73
|
-
Defined in: [actioncode.ts:217](https://github.com/otaprotocol/actioncodes/blob/
|
73
|
+
Defined in: [actioncode.ts:217](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L217)
|
74
74
|
|
75
75
|
Get the code hash for this action code
|
76
76
|
it is also used in the protocol meta as the code id
|
@@ -89,7 +89,7 @@ Code hash string
|
|
89
89
|
|
90
90
|
> **get** **description**(): `undefined` \| `string`
|
91
91
|
|
92
|
-
Defined in: [actioncode.ts:151](https://github.com/otaprotocol/actioncodes/blob/
|
92
|
+
Defined in: [actioncode.ts:151](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L151)
|
93
93
|
|
94
94
|
Get a human-readable description of the action
|
95
95
|
|
@@ -107,7 +107,7 @@ Description string or undefined
|
|
107
107
|
|
108
108
|
> **get** **displayString**(): `string`
|
109
109
|
|
110
|
-
Defined in: [actioncode.ts:183](https://github.com/otaprotocol/actioncodes/blob/
|
110
|
+
Defined in: [actioncode.ts:183](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L183)
|
111
111
|
|
112
112
|
Get a human-readable display string for the action code
|
113
113
|
|
@@ -125,7 +125,7 @@ Formatted display string
|
|
125
125
|
|
126
126
|
> **get** **encoded**(): `string`
|
127
127
|
|
128
|
-
Defined in: [actioncode.ts:47](https://github.com/otaprotocol/actioncodes/blob/
|
128
|
+
Defined in: [actioncode.ts:47](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L47)
|
129
129
|
|
130
130
|
##### Returns
|
131
131
|
|
@@ -139,7 +139,7 @@ Defined in: [actioncode.ts:47](https://github.com/otaprotocol/actioncodes/blob/0
|
|
139
139
|
|
140
140
|
> **get** **expired**(): `boolean`
|
141
141
|
|
142
|
-
Defined in: [actioncode.ts:87](https://github.com/otaprotocol/actioncodes/blob/
|
142
|
+
Defined in: [actioncode.ts:87](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L87)
|
143
143
|
|
144
144
|
Check if the action code has expired
|
145
145
|
|
@@ -157,7 +157,7 @@ True if the code has expired
|
|
157
157
|
|
158
158
|
> **get** **json**(): [`ActionCodeFields`](../interfaces/ActionCodeFields.md)
|
159
159
|
|
160
|
-
Defined in: [actioncode.ts:68](https://github.com/otaprotocol/actioncodes/blob/
|
160
|
+
Defined in: [actioncode.ts:68](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L68)
|
161
161
|
|
162
162
|
##### Returns
|
163
163
|
|
@@ -171,7 +171,7 @@ Defined in: [actioncode.ts:68](https://github.com/otaprotocol/actioncodes/blob/0
|
|
171
171
|
|
172
172
|
> **get** **metadata**(): `undefined` \| [`ActionCodeMetadata`](../interfaces/ActionCodeMetadata.md)
|
173
173
|
|
174
|
-
Defined in: [actioncode.ts:143](https://github.com/otaprotocol/actioncodes/blob/
|
174
|
+
Defined in: [actioncode.ts:143](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L143)
|
175
175
|
|
176
176
|
Get metadata associated with this action code
|
177
177
|
|
@@ -189,7 +189,7 @@ Metadata object or undefined
|
|
189
189
|
|
190
190
|
> **get** **params**(): `undefined` \| `Record`\<`string`, `any`\>
|
191
191
|
|
192
|
-
Defined in: [actioncode.ts:159](https://github.com/otaprotocol/actioncodes/blob/
|
192
|
+
Defined in: [actioncode.ts:159](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L159)
|
193
193
|
|
194
194
|
Get parameters associated with this action
|
195
195
|
|
@@ -207,7 +207,7 @@ Parameters object or undefined
|
|
207
207
|
|
208
208
|
> **get** **prefix**(): `string`
|
209
209
|
|
210
|
-
Defined in: [actioncode.ts:119](https://github.com/otaprotocol/actioncodes/blob/
|
210
|
+
Defined in: [actioncode.ts:119](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L119)
|
211
211
|
|
212
212
|
Get the prefix used for this action code
|
213
213
|
|
@@ -225,7 +225,7 @@ Normalized prefix
|
|
225
225
|
|
226
226
|
> **get** **pubkey**(): `string`
|
227
227
|
|
228
|
-
Defined in: [actioncode.ts:127](https://github.com/otaprotocol/actioncodes/blob/
|
228
|
+
Defined in: [actioncode.ts:127](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L127)
|
229
229
|
|
230
230
|
Get the user's public key
|
231
231
|
|
@@ -243,7 +243,7 @@ User's public key
|
|
243
243
|
|
244
244
|
> **get** **remainingTime**(): `number`
|
245
245
|
|
246
|
-
Defined in: [actioncode.ts:78](https://github.com/otaprotocol/actioncodes/blob/
|
246
|
+
Defined in: [actioncode.ts:78](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L78)
|
247
247
|
|
248
248
|
Get remaining time in milliseconds until expiration
|
249
249
|
|
@@ -261,7 +261,7 @@ Remaining time in milliseconds, or 0 if expired
|
|
261
261
|
|
262
262
|
> **get** **remainingTimeString**(): `string`
|
263
263
|
|
264
|
-
Defined in: [actioncode.ts:196](https://github.com/otaprotocol/actioncodes/blob/
|
264
|
+
Defined in: [actioncode.ts:196](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L196)
|
265
265
|
|
266
266
|
Get a formatted time string showing remaining time
|
267
267
|
|
@@ -279,7 +279,7 @@ Human-readable time string (e.g., "1m 30s remaining")
|
|
279
279
|
|
280
280
|
> **get** **signature**(): `string`
|
281
281
|
|
282
|
-
Defined in: [actioncode.ts:175](https://github.com/otaprotocol/actioncodes/blob/
|
282
|
+
Defined in: [actioncode.ts:175](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L175)
|
283
283
|
|
284
284
|
Get the user's signature
|
285
285
|
|
@@ -297,7 +297,7 @@ User's signature string
|
|
297
297
|
|
298
298
|
> **get** **status**(): [`ActionCodeStatus`](../type-aliases/ActionCodeStatus.md)
|
299
299
|
|
300
|
-
Defined in: [actioncode.ts:103](https://github.com/otaprotocol/actioncodes/blob/
|
300
|
+
Defined in: [actioncode.ts:103](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L103)
|
301
301
|
|
302
302
|
Get the current status of the action code
|
303
303
|
|
@@ -315,7 +315,7 @@ Current status
|
|
315
315
|
|
316
316
|
> **get** **timestamp**(): `number`
|
317
317
|
|
318
|
-
Defined in: [actioncode.ts:167](https://github.com/otaprotocol/actioncodes/blob/
|
318
|
+
Defined in: [actioncode.ts:167](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L167)
|
319
319
|
|
320
320
|
Get the timestamp when the code was generated
|
321
321
|
|
@@ -333,7 +333,7 @@ Timestamp in milliseconds
|
|
333
333
|
|
334
334
|
> **get** **transaction**(): `undefined` \| [`ActionCodeTransaction`](../interfaces/ActionCodeTransaction.md)
|
335
335
|
|
336
|
-
Defined in: [actioncode.ts:135](https://github.com/otaprotocol/actioncodes/blob/
|
336
|
+
Defined in: [actioncode.ts:135](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L135)
|
337
337
|
|
338
338
|
Get the transaction data (chain-specific)
|
339
339
|
|
@@ -349,7 +349,7 @@ Transaction data or undefined
|
|
349
349
|
|
350
350
|
> **isValid**(`protocol`): `boolean`
|
351
351
|
|
352
|
-
Defined in: [actioncode.ts:51](https://github.com/otaprotocol/actioncodes/blob/
|
352
|
+
Defined in: [actioncode.ts:51](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L51)
|
353
353
|
|
354
354
|
#### Parameters
|
355
355
|
|
@@ -367,7 +367,7 @@ Defined in: [actioncode.ts:51](https://github.com/otaprotocol/actioncodes/blob/0
|
|
367
367
|
|
368
368
|
> `static` **fromEncoded**(`encoded`): `ActionCode`
|
369
369
|
|
370
|
-
Defined in: [actioncode.ts:42](https://github.com/otaprotocol/actioncodes/blob/
|
370
|
+
Defined in: [actioncode.ts:42](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L42)
|
371
371
|
|
372
372
|
#### Parameters
|
373
373
|
|
@@ -385,7 +385,7 @@ Defined in: [actioncode.ts:42](https://github.com/otaprotocol/actioncodes/blob/0
|
|
385
385
|
|
386
386
|
> `static` **fromPayload**(`input`): `ActionCode`
|
387
387
|
|
388
|
-
Defined in: [actioncode.ts:35](https://github.com/otaprotocol/actioncodes/blob/
|
388
|
+
Defined in: [actioncode.ts:35](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L35)
|
389
389
|
|
390
390
|
#### Parameters
|
391
391
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
# Interface: ActionCodeFields
|
8
8
|
|
9
|
-
Defined in: [actioncode.ts:19](https://github.com/otaprotocol/actioncodes/blob/
|
9
|
+
Defined in: [actioncode.ts:19](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L19)
|
10
10
|
|
11
11
|
## Properties
|
12
12
|
|
@@ -14,7 +14,7 @@ Defined in: [actioncode.ts:19](https://github.com/otaprotocol/actioncodes/blob/0
|
|
14
14
|
|
15
15
|
> **chain**: `"solana"`
|
16
16
|
|
17
|
-
Defined in: [actioncode.ts:25](https://github.com/otaprotocol/actioncodes/blob/
|
17
|
+
Defined in: [actioncode.ts:25](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L25)
|
18
18
|
|
19
19
|
***
|
20
20
|
|
@@ -22,7 +22,7 @@ Defined in: [actioncode.ts:25](https://github.com/otaprotocol/actioncodes/blob/0
|
|
22
22
|
|
23
23
|
> **code**: `string`
|
24
24
|
|
25
|
-
Defined in: [actioncode.ts:20](https://github.com/otaprotocol/actioncodes/blob/
|
25
|
+
Defined in: [actioncode.ts:20](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L20)
|
26
26
|
|
27
27
|
***
|
28
28
|
|
@@ -30,7 +30,7 @@ Defined in: [actioncode.ts:20](https://github.com/otaprotocol/actioncodes/blob/0
|
|
30
30
|
|
31
31
|
> **expiresAt**: `number`
|
32
32
|
|
33
|
-
Defined in: [actioncode.ts:28](https://github.com/otaprotocol/actioncodes/blob/
|
33
|
+
Defined in: [actioncode.ts:28](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L28)
|
34
34
|
|
35
35
|
***
|
36
36
|
|
@@ -38,7 +38,7 @@ Defined in: [actioncode.ts:28](https://github.com/otaprotocol/actioncodes/blob/0
|
|
38
38
|
|
39
39
|
> `optional` **metadata**: [`ActionCodeMetadata`](ActionCodeMetadata.md)
|
40
40
|
|
41
|
-
Defined in: [actioncode.ts:27](https://github.com/otaprotocol/actioncodes/blob/
|
41
|
+
Defined in: [actioncode.ts:27](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L27)
|
42
42
|
|
43
43
|
***
|
44
44
|
|
@@ -46,7 +46,7 @@ Defined in: [actioncode.ts:27](https://github.com/otaprotocol/actioncodes/blob/0
|
|
46
46
|
|
47
47
|
> **prefix**: `string`
|
48
48
|
|
49
|
-
Defined in: [actioncode.ts:21](https://github.com/otaprotocol/actioncodes/blob/
|
49
|
+
Defined in: [actioncode.ts:21](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L21)
|
50
50
|
|
51
51
|
***
|
52
52
|
|
@@ -54,7 +54,7 @@ Defined in: [actioncode.ts:21](https://github.com/otaprotocol/actioncodes/blob/0
|
|
54
54
|
|
55
55
|
> **pubkey**: `string`
|
56
56
|
|
57
|
-
Defined in: [actioncode.ts:22](https://github.com/otaprotocol/actioncodes/blob/
|
57
|
+
Defined in: [actioncode.ts:22](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L22)
|
58
58
|
|
59
59
|
***
|
60
60
|
|
@@ -62,7 +62,7 @@ Defined in: [actioncode.ts:22](https://github.com/otaprotocol/actioncodes/blob/0
|
|
62
62
|
|
63
63
|
> **signature**: `string`
|
64
64
|
|
65
|
-
Defined in: [actioncode.ts:24](https://github.com/otaprotocol/actioncodes/blob/
|
65
|
+
Defined in: [actioncode.ts:24](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L24)
|
66
66
|
|
67
67
|
***
|
68
68
|
|
@@ -70,7 +70,7 @@ Defined in: [actioncode.ts:24](https://github.com/otaprotocol/actioncodes/blob/0
|
|
70
70
|
|
71
71
|
> **status**: [`ActionCodeStatus`](../type-aliases/ActionCodeStatus.md)
|
72
72
|
|
73
|
-
Defined in: [actioncode.ts:29](https://github.com/otaprotocol/actioncodes/blob/
|
73
|
+
Defined in: [actioncode.ts:29](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L29)
|
74
74
|
|
75
75
|
***
|
76
76
|
|
@@ -78,7 +78,7 @@ Defined in: [actioncode.ts:29](https://github.com/otaprotocol/actioncodes/blob/0
|
|
78
78
|
|
79
79
|
> **timestamp**: `number`
|
80
80
|
|
81
|
-
Defined in: [actioncode.ts:23](https://github.com/otaprotocol/actioncodes/blob/
|
81
|
+
Defined in: [actioncode.ts:23](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L23)
|
82
82
|
|
83
83
|
***
|
84
84
|
|
@@ -86,4 +86,4 @@ Defined in: [actioncode.ts:23](https://github.com/otaprotocol/actioncodes/blob/0
|
|
86
86
|
|
87
87
|
> `optional` **transaction**: [`ActionCodeTransaction`](ActionCodeTransaction.md)
|
88
88
|
|
89
|
-
Defined in: [actioncode.ts:26](https://github.com/otaprotocol/actioncodes/blob/
|
89
|
+
Defined in: [actioncode.ts:26](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L26)
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
# Interface: ActionCodeMetadata
|
8
8
|
|
9
|
-
Defined in: [actioncode.ts:8](https://github.com/otaprotocol/actioncodes/blob/
|
9
|
+
Defined in: [actioncode.ts:8](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L8)
|
10
10
|
|
11
11
|
## Properties
|
12
12
|
|
@@ -14,7 +14,7 @@ Defined in: [actioncode.ts:8](https://github.com/otaprotocol/actioncodes/blob/00
|
|
14
14
|
|
15
15
|
> `optional` **description**: `string`
|
16
16
|
|
17
|
-
Defined in: [actioncode.ts:9](https://github.com/otaprotocol/actioncodes/blob/
|
17
|
+
Defined in: [actioncode.ts:9](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L9)
|
18
18
|
|
19
19
|
***
|
20
20
|
|
@@ -22,4 +22,4 @@ Defined in: [actioncode.ts:9](https://github.com/otaprotocol/actioncodes/blob/00
|
|
22
22
|
|
23
23
|
> `optional` **params**: `Record`\<`string`, `any`\>
|
24
24
|
|
25
|
-
Defined in: [actioncode.ts:10](https://github.com/otaprotocol/actioncodes/blob/
|
25
|
+
Defined in: [actioncode.ts:10](https://github.com/otaprotocol/actioncodes/blob/57f8663219c9af5c455731c797e721cd72058ff4/src/actioncode.ts#L10)
|