@actioncodes/protocol 1.0.0 → 1.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.
- package/dist/actioncode.d.ts +13 -12
- package/dist/actioncode.d.ts.map +1 -1
- package/dist/actioncode.js +13 -5
- package/dist/adapters/base.d.ts +17 -0
- package/dist/adapters/base.d.ts.map +1 -1
- package/dist/adapters/base.js +11 -0
- package/dist/adapters/solana/solana.d.ts +2 -0
- package/dist/adapters/solana/solana.d.ts.map +1 -1
- package/dist/adapters/solana/solana.js +49 -2
- package/dist/codegen.d.ts +3 -13
- package/dist/codegen.d.ts.map +1 -1
- package/dist/codegen.js +6 -18
- package/dist/protocol.d.ts +14 -14
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +39 -30
- package/docs/actioncode/classes/ActionCode.md +51 -65
- package/docs/actioncode/interfaces/ActionCodeFields.md +13 -19
- package/docs/actioncode/interfaces/ActionCodeMetadata.md +3 -3
- package/docs/actioncode/interfaces/ActionCodeTransaction.md +6 -12
- package/docs/actioncode/type-aliases/ActionCodeStatus.md +1 -1
- package/docs/adapters/base/classes/BaseChainAdapter.md +70 -8
- package/docs/adapters/solana/solana/classes/SolanaAdapter.md +80 -10
- package/docs/adapters/solana/solana/type-aliases/SolanaTransaction.md +1 -1
- package/docs/codegen/classes/CodeGenerator.md +15 -63
- 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 +76 -76
- package/docs/protocol/interfaces/ProtocolConfig.md +7 -7
- package/package.json +2 -1
package/dist/actioncode.d.ts
CHANGED
@@ -1,34 +1,35 @@
|
|
1
1
|
import { SUPPORTED_CHAINS } from "./constants";
|
2
|
+
import { ActionCodesProtocol } from "./protocol";
|
2
3
|
export type ActionCodeStatus = 'pending' | 'resolved' | 'finalized' | 'expired' | 'error';
|
3
4
|
export interface ActionCodeMetadata {
|
4
5
|
description?: string;
|
5
6
|
params?: Record<string, any>;
|
6
7
|
}
|
7
|
-
export interface ActionCodeTransaction
|
8
|
-
transaction?:
|
8
|
+
export interface ActionCodeTransaction {
|
9
|
+
transaction?: string;
|
9
10
|
txSignature?: string;
|
10
11
|
txType?: string;
|
11
12
|
}
|
12
|
-
export interface ActionCodeFields
|
13
|
+
export interface ActionCodeFields {
|
13
14
|
code: string;
|
14
15
|
prefix: string;
|
15
16
|
pubkey: string;
|
16
17
|
timestamp: number;
|
17
18
|
signature: string;
|
18
19
|
chain: (typeof SUPPORTED_CHAINS)[number];
|
19
|
-
transaction?: ActionCodeTransaction
|
20
|
+
transaction?: ActionCodeTransaction;
|
20
21
|
metadata?: ActionCodeMetadata;
|
21
22
|
expiresAt: number;
|
22
23
|
status: ActionCodeStatus;
|
23
24
|
}
|
24
|
-
export declare class ActionCode
|
25
|
+
export declare class ActionCode {
|
25
26
|
private fields;
|
26
|
-
constructor(fields: ActionCodeFields
|
27
|
-
static fromPayload
|
28
|
-
static fromEncoded
|
27
|
+
constructor(fields: ActionCodeFields);
|
28
|
+
static fromPayload(input: ActionCodeFields): ActionCode;
|
29
|
+
static fromEncoded(encoded: string): ActionCode;
|
29
30
|
get encoded(): string;
|
30
|
-
|
31
|
-
get json(): ActionCodeFields
|
31
|
+
isValid(protocol: ActionCodesProtocol): boolean;
|
32
|
+
get json(): ActionCodeFields;
|
32
33
|
/**
|
33
34
|
* Get remaining time in milliseconds until expiration
|
34
35
|
* @returns Remaining time in milliseconds, or 0 if expired
|
@@ -68,12 +69,12 @@ export declare class ActionCode<T> {
|
|
68
69
|
* Get the transaction data (chain-specific)
|
69
70
|
* @returns Transaction data or undefined
|
70
71
|
*/
|
71
|
-
get transaction(): ActionCodeTransaction
|
72
|
+
get transaction(): ActionCodeTransaction | undefined;
|
72
73
|
/**
|
73
74
|
* Get metadata associated with this action code
|
74
75
|
* @returns Metadata object or undefined
|
75
76
|
*/
|
76
|
-
get metadata(): ActionCodeFields
|
77
|
+
get metadata(): ActionCodeFields['metadata'] | undefined;
|
77
78
|
/**
|
78
79
|
* Get a human-readable description of the action
|
79
80
|
* @returns Description string or undefined
|
package/dist/actioncode.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"actioncode.d.ts","sourceRoot":"","sources":["../src/actioncode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"actioncode.d.ts","sourceRoot":"","sources":["../src/actioncode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGjD,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE1F,MAAM,WAAW,kBAAkB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,qBAAqB;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb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,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAE5C;IAED;;;OAGG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;;OAGG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;;OAGG;IACH,IAAI,aAAa,IAAI,MAAM,CAO1B;IAED;;;OAGG;IACH,IAAI,mBAAmB,IAAI,MAAM,CAchC;IAED;;;;OAIG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;CACJ"}
|
package/dist/actioncode.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.ActionCode = void 0;
|
4
4
|
const codegen_1 = require("./codegen");
|
5
|
+
const buffer_1 = require("buffer");
|
5
6
|
class ActionCode {
|
6
7
|
constructor(fields) {
|
7
8
|
this.fields = fields;
|
@@ -13,14 +14,21 @@ class ActionCode {
|
|
13
14
|
return new ActionCode(input);
|
14
15
|
}
|
15
16
|
static fromEncoded(encoded) {
|
16
|
-
const decoded = JSON.parse(
|
17
|
+
const decoded = JSON.parse(buffer_1.Buffer.from(encoded, 'base64').toString('utf8'));
|
17
18
|
return ActionCode.fromPayload(decoded);
|
18
19
|
}
|
19
20
|
get encoded() {
|
20
|
-
return
|
21
|
-
}
|
22
|
-
|
23
|
-
|
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;
|
24
32
|
}
|
25
33
|
get json() {
|
26
34
|
return this.fields;
|
package/dist/adapters/base.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { ActionCode } from '../actioncode';
|
1
2
|
import { ProtocolMetaV1 } from '../meta';
|
2
3
|
/**
|
3
4
|
* Base adapter class for chain-specific protocol meta operations
|
@@ -48,5 +49,21 @@ export declare abstract class BaseChainAdapter<T = any> {
|
|
48
49
|
* @returns True if transaction integrity is valid
|
49
50
|
*/
|
50
51
|
protected abstract validateTransactionIntegrity(tx: T, meta: ProtocolMetaV1): boolean;
|
52
|
+
/**
|
53
|
+
* Get the code signature message
|
54
|
+
* @param code - The code to sign
|
55
|
+
* @param timestamp - The timestamp of the code
|
56
|
+
* @param prefix - The prefix of the code
|
57
|
+
* @returns The code signature message
|
58
|
+
*/
|
59
|
+
getCodeSignatureMessage(code: string, timestamp: number, prefix?: string): string;
|
60
|
+
/**
|
61
|
+
* Verify the code signature
|
62
|
+
* This is specific to the chain and should be implemented by the concrete adapter
|
63
|
+
* It will be used to verify the code signature for the action code if the right wallet is used to sign the code
|
64
|
+
* @param actionCode - The action code to verify
|
65
|
+
* @returns True if the code signature is valid
|
66
|
+
*/
|
67
|
+
abstract verifyCodeSignature(actionCode: ActionCode): boolean;
|
51
68
|
}
|
52
69
|
//# 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,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,MAAM,CAAC,IAAI,EAAE,cAAc,GAAG,GAAG;IAE1C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,G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;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;CAChE"}
|
package/dist/adapters/base.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.BaseChainAdapter = void 0;
|
4
|
+
const constants_1 = require("../constants");
|
4
5
|
/**
|
5
6
|
* Base adapter class for chain-specific protocol meta operations
|
6
7
|
* @template T - Chain-specific transaction type
|
@@ -37,5 +38,15 @@ class BaseChainAdapter {
|
|
37
38
|
// Additional chain-specific validation
|
38
39
|
return this.validateTransactionIntegrity(tx, meta);
|
39
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
|
+
}
|
40
51
|
}
|
41
52
|
exports.BaseChainAdapter = BaseChainAdapter;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
2
2
|
import { ProtocolMetaV1 } from '../../meta';
|
3
3
|
import { BaseChainAdapter } from '../base';
|
4
|
+
import { ActionCode } from '../../actioncode';
|
4
5
|
/**
|
5
6
|
* Solana transaction type union
|
6
7
|
*/
|
@@ -80,5 +81,6 @@ export declare class SolanaAdapter extends BaseChainAdapter<SolanaTransaction> {
|
|
80
81
|
* @returns True if transaction is valid
|
81
82
|
*/
|
82
83
|
validateFromBase64(base64String: string, authorities: string[], expectedPrefix?: string): boolean;
|
84
|
+
verifyCodeSignature(actionCode: ActionCode): boolean;
|
83
85
|
}
|
84
86
|
//# 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,EAGvB,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,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,MAAM,CAAC,IAAI,EAAE,cAAc,GAAG,sBAAsB;IAKpD;;;;OAIG;IACH,MAAM,CAAC,EAAE,EAAE,iBAAiB,GAAG,cAAc,GAAG,IAAI;IAWpD;;;;;;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,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAWlE;;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;IAqB5F;;;;OAIG;IACH,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAgB7D;;;;;;OAMG;IACH,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,cAAc,GAAE,MAAkB,GAAG,OAAO;IAiBrG,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;CAY9D"}
|
@@ -1,10 +1,45 @@
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
36
|
exports.SolanaAdapter = void 0;
|
4
37
|
const web3_js_1 = require("@solana/web3.js");
|
5
38
|
const spl_memo_1 = require("@solana/spl-memo");
|
6
39
|
const meta_1 = require("../../meta");
|
7
40
|
const base_1 = require("../base");
|
41
|
+
const nacl = __importStar(require("tweetnacl"));
|
42
|
+
const buffer_1 = require("buffer");
|
8
43
|
/**
|
9
44
|
* Simple Solana adapter for protocol meta operations
|
10
45
|
* Supports both legacy and versioned transactions
|
@@ -179,7 +214,7 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
179
214
|
*/
|
180
215
|
decodeFromBase64(base64String) {
|
181
216
|
try {
|
182
|
-
const buffer =
|
217
|
+
const buffer = buffer_1.Buffer.from(base64String, 'base64');
|
183
218
|
// Try legacy first, then versioned
|
184
219
|
try {
|
185
220
|
const transaction = web3_js_1.Transaction.from(buffer);
|
@@ -203,7 +238,7 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
203
238
|
*/
|
204
239
|
validateFromBase64(base64String, authorities, expectedPrefix = 'DEFAULT') {
|
205
240
|
try {
|
206
|
-
const buffer =
|
241
|
+
const buffer = buffer_1.Buffer.from(base64String, 'base64');
|
207
242
|
// Try legacy first, then versioned
|
208
243
|
try {
|
209
244
|
const transaction = web3_js_1.Transaction.from(buffer);
|
@@ -218,6 +253,18 @@ class SolanaAdapter extends base_1.BaseChainAdapter {
|
|
218
253
|
return false;
|
219
254
|
}
|
220
255
|
}
|
256
|
+
verifyCodeSignature(actionCode) {
|
257
|
+
try {
|
258
|
+
const message = this.getCodeSignatureMessage(actionCode.code, actionCode.timestamp, actionCode.prefix);
|
259
|
+
const messageBytes = new TextEncoder().encode(message);
|
260
|
+
const pubkeyBytes = new web3_js_1.PublicKey(actionCode.pubkey).toBytes();
|
261
|
+
const sigBytes = buffer_1.Buffer.from(actionCode.signature, 'base64');
|
262
|
+
return nacl.sign.detached.verify(messageBytes, sigBytes, pubkeyBytes);
|
263
|
+
}
|
264
|
+
catch (error) {
|
265
|
+
return false;
|
266
|
+
}
|
267
|
+
}
|
221
268
|
}
|
222
269
|
exports.SolanaAdapter = SolanaAdapter;
|
223
270
|
SolanaAdapter.MEMO_PROGRAM_ID = spl_memo_1.MEMO_PROGRAM_ID;
|
package/dist/codegen.d.ts
CHANGED
@@ -19,12 +19,11 @@ export declare class CodeGenerator {
|
|
19
19
|
/**
|
20
20
|
* Generate a deterministic 8-digit code based on public key, prefix, and timestamp
|
21
21
|
* @param pubkey - Solana wallet public key (base58)
|
22
|
-
* @param signature - User's signature string
|
23
22
|
* @param prefix - Optional namespace prefix (default: "DEFAULT")
|
24
23
|
* @param timestamp - UNIX timestamp in milliseconds (defaults to now)
|
25
24
|
* @returns Object containing code, issuedAt, and expiresAt timestamps
|
26
25
|
*/
|
27
|
-
static generateCode(pubkey: string,
|
26
|
+
static generateCode(pubkey: string, prefix?: string, timestamp?: number): {
|
28
27
|
code: string;
|
29
28
|
issuedAt: number;
|
30
29
|
expiresAt: number;
|
@@ -37,32 +36,23 @@ export declare class CodeGenerator {
|
|
37
36
|
* @returns Full SHA-256 hash string
|
38
37
|
*/
|
39
38
|
static deriveCodeHash(pubkey: string, prefix?: string, timestamp?: number): string;
|
40
|
-
/**
|
41
|
-
* Generate the message that should be signed for code verification
|
42
|
-
* @param code - The generated 8-digit code
|
43
|
-
* @param timestamp - UNIX timestamp in milliseconds
|
44
|
-
* @returns Message string in format "actioncodes:<code>:<timestamp>"
|
45
|
-
*/
|
46
|
-
static generateCodeSignatureMessage(code: string, timestamp: number): string;
|
47
39
|
/**
|
48
40
|
* Get the expected code for a given public key and timestamp
|
49
41
|
* @param pubkey - Solana wallet public key (base58)
|
50
42
|
* @param timestamp - UNIX timestamp in milliseconds
|
51
|
-
* @param signature - User's signature string
|
52
43
|
* @param prefix - Optional namespace prefix (default: "DEFAULT")
|
53
44
|
* @returns 8-digit numeric string
|
54
45
|
*/
|
55
|
-
static getExpectedCode(pubkey: string, timestamp: number,
|
46
|
+
static getExpectedCode(pubkey: string, timestamp: number, prefix?: string): string;
|
56
47
|
/**
|
57
48
|
* Validate if a code matches the expected code for a given public key and timestamp
|
58
49
|
* @param code - The code to validate
|
59
50
|
* @param pubkey - Solana wallet public key (base58)
|
60
51
|
* @param timestamp - UNIX timestamp in milliseconds
|
61
|
-
* @param signature - User's signature string
|
62
52
|
* @param prefix - Optional namespace prefix (default: "DEFAULT")
|
63
53
|
* @returns True if code matches expected code and timestamp is valid
|
64
54
|
*/
|
65
|
-
static validateCode(code: string, pubkey: string, timestamp: number,
|
55
|
+
static validateCode(code: string, pubkey: string, timestamp: number, prefix?: string): boolean;
|
66
56
|
/**
|
67
57
|
* Check if a timestamp falls within a valid time window
|
68
58
|
* @param timestamp - UNIX timestamp in milliseconds
|
package/dist/codegen.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAGA,qBAAa,aAAa;IACtB,MAAM,CAAC,cAAc,SAAY;IACjC,MAAM,CAAC,WAAW,SAAe;I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AAO;IAOV;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;CAGtD"}
|
package/dist/codegen.js
CHANGED
@@ -33,14 +33,13 @@ class CodeGenerator {
|
|
33
33
|
/**
|
34
34
|
* Generate a deterministic 8-digit code based on public key, prefix, and timestamp
|
35
35
|
* @param pubkey - Solana wallet public key (base58)
|
36
|
-
* @param signature - User's signature string
|
37
36
|
* @param prefix - Optional namespace prefix (default: "DEFAULT")
|
38
37
|
* @param timestamp - UNIX timestamp in milliseconds (defaults to now)
|
39
38
|
* @returns Object containing code, issuedAt, and expiresAt timestamps
|
40
39
|
*/
|
41
|
-
static generateCode(pubkey,
|
40
|
+
static generateCode(pubkey, prefix = "DEFAULT", timestamp = Date.now()) {
|
42
41
|
const normalizedPrefix = this.normalizePrefix(prefix);
|
43
|
-
const input = `${normalizedPrefix}:${pubkey}:${timestamp}
|
42
|
+
const input = `${normalizedPrefix}:${pubkey}:${timestamp}`;
|
44
43
|
const hash = (0, js_sha256_1.sha256)(input);
|
45
44
|
const raw = parseInt(hash.slice(0, 16), 16);
|
46
45
|
const mod = 10 ** this.CODE_DIGITS;
|
@@ -67,37 +66,26 @@ class CodeGenerator {
|
|
67
66
|
const hash = (0, js_sha256_1.sha256)(input);
|
68
67
|
return hash;
|
69
68
|
}
|
70
|
-
/**
|
71
|
-
* Generate the message that should be signed for code verification
|
72
|
-
* @param code - The generated 8-digit code
|
73
|
-
* @param timestamp - UNIX timestamp in milliseconds
|
74
|
-
* @returns Message string in format "actioncodes:<code>:<timestamp>"
|
75
|
-
*/
|
76
|
-
static generateCodeSignatureMessage(code, timestamp) {
|
77
|
-
return `${constants_1.PROTOCOL_PREFIX}:${code}:${timestamp}`;
|
78
|
-
}
|
79
69
|
/**
|
80
70
|
* Get the expected code for a given public key and timestamp
|
81
71
|
* @param pubkey - Solana wallet public key (base58)
|
82
72
|
* @param timestamp - UNIX timestamp in milliseconds
|
83
|
-
* @param signature - User's signature string
|
84
73
|
* @param prefix - Optional namespace prefix (default: "DEFAULT")
|
85
74
|
* @returns 8-digit numeric string
|
86
75
|
*/
|
87
|
-
static getExpectedCode(pubkey, timestamp,
|
88
|
-
return this.generateCode(pubkey,
|
76
|
+
static getExpectedCode(pubkey, timestamp, prefix = "DEFAULT") {
|
77
|
+
return this.generateCode(pubkey, prefix, timestamp).code;
|
89
78
|
}
|
90
79
|
/**
|
91
80
|
* Validate if a code matches the expected code for a given public key and timestamp
|
92
81
|
* @param code - The code to validate
|
93
82
|
* @param pubkey - Solana wallet public key (base58)
|
94
83
|
* @param timestamp - UNIX timestamp in milliseconds
|
95
|
-
* @param signature - User's signature string
|
96
84
|
* @param prefix - Optional namespace prefix (default: "DEFAULT")
|
97
85
|
* @returns True if code matches expected code and timestamp is valid
|
98
86
|
*/
|
99
|
-
static validateCode(code, pubkey, timestamp,
|
100
|
-
const expectedCode = this.getExpectedCode(pubkey, timestamp,
|
87
|
+
static validateCode(code, pubkey, timestamp, prefix = "DEFAULT") {
|
88
|
+
const expectedCode = this.getExpectedCode(pubkey, timestamp, prefix);
|
101
89
|
const now = Date.now();
|
102
90
|
const isTimeValid = timestamp >= 0 && timestamp <= now && now <= timestamp + this.TIME_WINDOW_MS;
|
103
91
|
return code === expectedCode && isTimeValid;
|
package/dist/protocol.d.ts
CHANGED
@@ -51,22 +51,22 @@ export declare class ActionCodesProtocol {
|
|
51
51
|
* @returns Chain adapter or undefined
|
52
52
|
*/
|
53
53
|
getChainAdapter<T = any>(chain: string): BaseChainAdapter<T> | undefined;
|
54
|
-
/**
|
55
|
-
* Generate an action code for a specific chain
|
56
|
-
* @param pubkey - User's public key
|
57
|
-
* @param signature - User's signature
|
58
|
-
* @param chain - Target chain
|
59
|
-
* @param prefix - Optional prefix (defaults to config defaultPrefix)
|
60
|
-
* @param timestamp - Optional timestamp (defaults to now)
|
61
|
-
* @returns ActionCode object
|
62
|
-
*/
|
63
|
-
generateActionCode(pubkey: string, signature: string, chain: SupportedChain, prefix?: string, timestamp?: number): ActionCode<string>;
|
64
54
|
/**
|
65
55
|
* Validate an action code
|
66
56
|
* @param actionCode - ActionCode to validate
|
67
57
|
* @returns True if valid
|
68
58
|
*/
|
69
|
-
validateActionCode(actionCode: ActionCode
|
59
|
+
validateActionCode(actionCode: ActionCode): boolean;
|
60
|
+
/**
|
61
|
+
* Create an action code
|
62
|
+
* @param pubkey - Wallet public key
|
63
|
+
* @param signFn - Chain-specific signing function (e.g.wallet.signMessage)
|
64
|
+
* @param chain - Target blockchain
|
65
|
+
* @param prefix - Optional code prefix
|
66
|
+
* @param timestamp - Optional timestamp
|
67
|
+
* @returns Promise resolving to a complete ActionCode object
|
68
|
+
*/
|
69
|
+
createActionCode(pubkey: string, signFn: (message: string) => Promise<string>, chain: SupportedChain, prefix?: string, timestamp?: number): Promise<ActionCode>;
|
70
70
|
/**
|
71
71
|
* Attach a transaction to an action code
|
72
72
|
* @param actionCode - ActionCode to attach transaction to
|
@@ -74,14 +74,14 @@ export declare class ActionCodesProtocol {
|
|
74
74
|
* @param txType - Optional transaction type
|
75
75
|
* @returns Updated ActionCode
|
76
76
|
*/
|
77
|
-
attachTransaction(actionCode: ActionCode
|
77
|
+
attachTransaction(actionCode: ActionCode, transaction: string, txType?: string): ActionCode;
|
78
78
|
/**
|
79
79
|
* Finalize an action code with transaction signature
|
80
80
|
* @param actionCode - ActionCode to finalize
|
81
81
|
* @param txSignature - Transaction signature
|
82
82
|
* @returns Updated ActionCode
|
83
83
|
*/
|
84
|
-
finalizeActionCode(actionCode: ActionCode
|
84
|
+
finalizeActionCode(actionCode: ActionCode, txSignature: string): ActionCode;
|
85
85
|
/**
|
86
86
|
* Create protocol meta for a transaction
|
87
87
|
* @param actionCode - ActionCode to create meta for
|
@@ -89,7 +89,7 @@ export declare class ActionCodesProtocol {
|
|
89
89
|
* @param params - Optional parameters
|
90
90
|
* @returns ProtocolMetaV1 object
|
91
91
|
*/
|
92
|
-
createProtocolMeta(actionCode: ActionCode
|
92
|
+
createProtocolMeta(actionCode: ActionCode, issuer?: string, params?: string): ProtocolMetaV1;
|
93
93
|
/**
|
94
94
|
* Encode protocol meta for a specific chain
|
95
95
|
* @param meta - ProtocolMetaV1 object
|
package/dist/protocol.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAAE,UAAU,EAA2C,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAA8D,cAAc,EAA2C,MAAM,aAAa,CAAC;AAElJ;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,4BAA4B;IAC5B,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;GAKG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,QAAQ,CAAiD;gBAErD,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAY5C;;;OAGG;IACH,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI;IAItD;;;OAGG;IACH,mBAAmB,IAAI,MAAM,EAAE;IAI/B;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIxC;;;;OAIG;IACH,eAAe,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAA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AE,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAShF;;;OAGG;IACH,SAAS,IAAI,cAAc;IAI3B;;;OAGG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;IAIpD;;;OAGG;IACH,MAAM,CAAC,MAAM,IAAI,mBAAmB;IAIpC;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,mBAAmB;CAGhF;AAGD,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACxF,YAAY,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAG7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/protocol.js
CHANGED
@@ -54,36 +54,6 @@ class ActionCodesProtocol {
|
|
54
54
|
getChainAdapter(chain) {
|
55
55
|
return this.adapters.get(chain);
|
56
56
|
}
|
57
|
-
/**
|
58
|
-
* Generate an action code for a specific chain
|
59
|
-
* @param pubkey - User's public key
|
60
|
-
* @param signature - User's signature
|
61
|
-
* @param chain - Target chain
|
62
|
-
* @param prefix - Optional prefix (defaults to config defaultPrefix)
|
63
|
-
* @param timestamp - Optional timestamp (defaults to now)
|
64
|
-
* @returns ActionCode object
|
65
|
-
*/
|
66
|
-
generateActionCode(pubkey, signature, chain, prefix, timestamp) {
|
67
|
-
if (!this.isChainSupported(chain)) {
|
68
|
-
throw new Error(`Chain '${chain}' is not supported. Registered chains: ${this.getRegisteredChains().join(', ')}`);
|
69
|
-
}
|
70
|
-
const normalizedPrefix = prefix || this.config.defaultPrefix;
|
71
|
-
const ts = timestamp || Date.now();
|
72
|
-
// Generate code using CodeGenerator
|
73
|
-
const { code, issuedAt, expiresAt } = codegen_1.CodeGenerator.generateCode(pubkey, signature, normalizedPrefix, ts);
|
74
|
-
// Create ActionCode object
|
75
|
-
const actionCodeFields = {
|
76
|
-
code,
|
77
|
-
prefix: normalizedPrefix,
|
78
|
-
pubkey,
|
79
|
-
timestamp: issuedAt,
|
80
|
-
signature,
|
81
|
-
chain,
|
82
|
-
expiresAt,
|
83
|
-
status: 'pending'
|
84
|
-
};
|
85
|
-
return actioncode_1.ActionCode.fromPayload(actionCodeFields);
|
86
|
-
}
|
87
57
|
/**
|
88
58
|
* Validate an action code
|
89
59
|
* @param actionCode - ActionCode to validate
|
@@ -101,6 +71,45 @@ class ActionCodesProtocol {
|
|
101
71
|
// Chain-specific validation would be done when attaching transactions
|
102
72
|
return true;
|
103
73
|
}
|
74
|
+
/**
|
75
|
+
* Create an action code
|
76
|
+
* @param pubkey - Wallet public key
|
77
|
+
* @param signFn - Chain-specific signing function (e.g.wallet.signMessage)
|
78
|
+
* @param chain - Target blockchain
|
79
|
+
* @param prefix - Optional code prefix
|
80
|
+
* @param timestamp - Optional timestamp
|
81
|
+
* @returns Promise resolving to a complete ActionCode object
|
82
|
+
*/
|
83
|
+
async createActionCode(pubkey, signFn, chain, prefix = this.config.defaultPrefix, timestamp) {
|
84
|
+
if (!this.isChainSupported(chain)) {
|
85
|
+
throw new Error(`Chain '${chain}' is not supported. Registered chains: ${this.getRegisteredChains().join(', ')}`);
|
86
|
+
}
|
87
|
+
const adapter = this.getChainAdapter(chain);
|
88
|
+
if (!adapter) {
|
89
|
+
throw new Error(`No adapter found for chain '${chain}'`);
|
90
|
+
}
|
91
|
+
const ts = timestamp || Date.now();
|
92
|
+
const { code, issuedAt, expiresAt } = codegen_1.CodeGenerator.generateCode(pubkey, prefix, ts);
|
93
|
+
const message = adapter.getCodeSignatureMessage(code, issuedAt, prefix);
|
94
|
+
const signature = await signFn(message);
|
95
|
+
const actionCode = actioncode_1.ActionCode.fromPayload({
|
96
|
+
code,
|
97
|
+
pubkey,
|
98
|
+
signature,
|
99
|
+
timestamp: issuedAt,
|
100
|
+
expiresAt,
|
101
|
+
prefix,
|
102
|
+
chain,
|
103
|
+
status: 'pending'
|
104
|
+
});
|
105
|
+
if (!this.validateActionCode(actionCode)) {
|
106
|
+
throw new Error('Invalid action code');
|
107
|
+
}
|
108
|
+
if (!adapter.verifyCodeSignature(actionCode)) {
|
109
|
+
throw new Error('Invalid signature for generated code');
|
110
|
+
}
|
111
|
+
return actionCode;
|
112
|
+
}
|
104
113
|
/**
|
105
114
|
* Attach a transaction to an action code
|
106
115
|
* @param actionCode - ActionCode to attach transaction to
|