@kynesyslabs/demosdk 2.4.0 → 2.4.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/build/abstraction/Identities.d.ts +10 -1
- package/build/abstraction/Identities.js +34 -4
- package/build/abstraction/Identities.js.map +1 -1
- package/build/contracts/templates/TemplateRegistry.d.ts +71 -0
- package/build/contracts/templates/TemplateRegistry.js +404 -0
- package/build/contracts/templates/TemplateRegistry.js.map +1 -0
- package/build/contracts/templates/TemplateValidator.d.ts +55 -0
- package/build/contracts/templates/TemplateValidator.js +202 -0
- package/build/contracts/templates/TemplateValidator.js.map +1 -0
- package/build/types/abstraction/index.d.ts +7 -1
- package/build/types/web2/discord.d.ts +8 -0
- package/build/types/web2/discord.js +3 -0
- package/build/types/web2/discord.js.map +1 -0
- package/build/websdk/DemosContracts.d.ts +55 -4
- package/build/websdk/DemosContracts.js +79 -64
- package/build/websdk/DemosContracts.js.map +1 -1
- package/build/websdk/demosclass.d.ts +6 -0
- package/build/websdk/demosclass.js +5 -0
- package/build/websdk/demosclass.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { XMCoreTargetIdentityPayload, Web2CoreTargetIdentityPayload, GithubProof, TwitterProof, InferFromSignaturePayload } from "../types/abstraction";
|
|
1
|
+
import { XMCoreTargetIdentityPayload, Web2CoreTargetIdentityPayload, GithubProof, TwitterProof, InferFromSignaturePayload, DiscordProof } from "../types/abstraction";
|
|
2
2
|
import { Demos } from "../websdk/demosclass";
|
|
3
3
|
import { PQCAlgorithm } from "../types/cryptography";
|
|
4
4
|
import { RPCResponseWithValidityData } from "../types";
|
|
@@ -7,6 +7,7 @@ export declare class Identities {
|
|
|
7
7
|
web2: {
|
|
8
8
|
github: string[];
|
|
9
9
|
twitter: string[];
|
|
10
|
+
discord: string[];
|
|
10
11
|
};
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
@@ -86,6 +87,14 @@ export declare class Identities {
|
|
|
86
87
|
* @returns The response from the RPC call.
|
|
87
88
|
*/
|
|
88
89
|
addTwitterIdentity(demos: Demos, payload: TwitterProof, referralCode?: string): Promise<RPCResponseWithValidityData>;
|
|
90
|
+
/**
|
|
91
|
+
* Add a discord identity to the GCR.
|
|
92
|
+
*
|
|
93
|
+
* @param demos A Demos instance to communicate with the RPC.
|
|
94
|
+
* @param payload The payload to add the identity to.
|
|
95
|
+
* @returns The response from the RPC call.
|
|
96
|
+
*/
|
|
97
|
+
addDiscordIdentity(demos: Demos, payload: DiscordProof, referralCode?: string): Promise<RPCResponseWithValidityData>;
|
|
89
98
|
bindPqcIdentity(demos: Demos, algorithms?: "all" | PQCAlgorithm[]): Promise<RPCResponseWithValidityData>;
|
|
90
99
|
removePqcIdentity(demos: Demos, algorithms?: "all" | PQCAlgorithm[]): Promise<RPCResponseWithValidityData>;
|
|
91
100
|
/**
|
|
@@ -19,6 +19,10 @@ class Identities {
|
|
|
19
19
|
"https://gist.githubusercontent.com",
|
|
20
20
|
],
|
|
21
21
|
twitter: ["https://x.com", "https://twitter.com"],
|
|
22
|
+
discord: [
|
|
23
|
+
"https://discord.com/channels",
|
|
24
|
+
"https://ptb.discord.com/channels",
|
|
25
|
+
],
|
|
22
26
|
},
|
|
23
27
|
};
|
|
24
28
|
}
|
|
@@ -110,7 +114,10 @@ class Identities {
|
|
|
110
114
|
* @returns The validity data of the identity transaction.
|
|
111
115
|
*/
|
|
112
116
|
async inferXmIdentity(demos, payload, referralCode) {
|
|
113
|
-
return await this.inferIdentity(demos, "xm", {
|
|
117
|
+
return await this.inferIdentity(demos, "xm", {
|
|
118
|
+
...payload,
|
|
119
|
+
referralCode: referralCode,
|
|
120
|
+
});
|
|
114
121
|
}
|
|
115
122
|
/**
|
|
116
123
|
* Infer a web2 identity from a proof payload.
|
|
@@ -189,6 +196,31 @@ class Identities {
|
|
|
189
196
|
};
|
|
190
197
|
return await this.inferIdentity(demos, "web2", twitterPayload);
|
|
191
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Add a discord identity to the GCR.
|
|
201
|
+
*
|
|
202
|
+
* @param demos A Demos instance to communicate with the RPC.
|
|
203
|
+
* @param payload The payload to add the identity to.
|
|
204
|
+
* @returns The response from the RPC call.
|
|
205
|
+
*/
|
|
206
|
+
async addDiscordIdentity(demos, payload, referralCode) {
|
|
207
|
+
const data = await demos.web2.getDiscordMessage(payload);
|
|
208
|
+
if (!data.success) {
|
|
209
|
+
throw new Error(data.error);
|
|
210
|
+
}
|
|
211
|
+
const msg = data.message;
|
|
212
|
+
if (!msg.authorId || !msg.authorUsername) {
|
|
213
|
+
throw new Error("Unable to get discord user info. Please try again.");
|
|
214
|
+
}
|
|
215
|
+
const discordPayload = {
|
|
216
|
+
context: "discord",
|
|
217
|
+
proof: payload,
|
|
218
|
+
username: msg.authorUsername,
|
|
219
|
+
userId: msg.authorId,
|
|
220
|
+
referralCode: referralCode,
|
|
221
|
+
};
|
|
222
|
+
return await this.inferIdentity(demos, "web2", discordPayload);
|
|
223
|
+
}
|
|
192
224
|
// SECTION: PQC Identities
|
|
193
225
|
async bindPqcIdentity(demos, algorithms = "all") {
|
|
194
226
|
let addressTypes = [];
|
|
@@ -337,9 +369,7 @@ class Identities {
|
|
|
337
369
|
}
|
|
338
370
|
const request = {
|
|
339
371
|
method: "gcr_routine",
|
|
340
|
-
params: [
|
|
341
|
-
{ method: "getReferralInfo", params: [address] },
|
|
342
|
-
],
|
|
372
|
+
params: [{ method: "getReferralInfo", params: [address] }],
|
|
343
373
|
};
|
|
344
374
|
return await demos.rpcCall(request, true);
|
|
345
375
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Identities.js","sourceRoot":"","sources":["../../../src/abstraction/Identities.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,8EAA8E;;;;;;AAE9E,kDAAyB;
|
|
1
|
+
{"version":3,"file":"Identities.js","sourceRoot":"","sources":["../../../src/abstraction/Identities.ts"],"names":[],"mapp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AMG;IACH,KAAK,CAAC,2BAA2B,CAAC,KAAY,EAAE,QAAgB;QAC5D,MAAM,OAAO,GAAG;YACZ,MAAM,EAAE,aAAa;YACrB,MAAM,EAAE;gBACJ,EAAE,MAAM,EAAE,6BAA6B,EAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE;aAChE;SACJ,CAAA;QAED,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC7C,CAAC;CACJ;AAxfD,gCAwfC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template Registry with Parameter Substitution
|
|
3
|
+
*
|
|
4
|
+
* Manages contract templates, validates parameters, and performs
|
|
5
|
+
* parameter substitution to generate deployable contract source code.
|
|
6
|
+
*/
|
|
7
|
+
import { TemplateSchema, ValidationResult } from './TemplateValidator';
|
|
8
|
+
export interface TemplateInfo {
|
|
9
|
+
name: string;
|
|
10
|
+
schema: TemplateSchema;
|
|
11
|
+
sourceFile: string;
|
|
12
|
+
source?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface SubstitutionResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
source?: string;
|
|
17
|
+
errors: string[];
|
|
18
|
+
warnings: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare class TemplateRegistry {
|
|
21
|
+
private static templates;
|
|
22
|
+
private static initialized;
|
|
23
|
+
/**
|
|
24
|
+
* Initialize the template registry with built-in templates
|
|
25
|
+
*/
|
|
26
|
+
static initialize(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Register a new template
|
|
29
|
+
*/
|
|
30
|
+
static registerTemplate(templateInfo: TemplateInfo): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get all available template names
|
|
33
|
+
*/
|
|
34
|
+
static getAvailableTemplates(): string[];
|
|
35
|
+
/**
|
|
36
|
+
* Get template information
|
|
37
|
+
*/
|
|
38
|
+
static getTemplate(name: string): TemplateInfo | null;
|
|
39
|
+
/**
|
|
40
|
+
* Get template schema for validation
|
|
41
|
+
*/
|
|
42
|
+
static getTemplateSchema(name: string): TemplateSchema | null;
|
|
43
|
+
/**
|
|
44
|
+
* Load template source code
|
|
45
|
+
*/
|
|
46
|
+
private static loadTemplateSource;
|
|
47
|
+
/**
|
|
48
|
+
* Get embedded template source (temporary implementation)
|
|
49
|
+
*/
|
|
50
|
+
private static getEmbeddedTemplateSource;
|
|
51
|
+
/**
|
|
52
|
+
* Validate template parameters
|
|
53
|
+
*/
|
|
54
|
+
static validateParameters(templateName: string, params: Record<string, any>): ValidationResult;
|
|
55
|
+
/**
|
|
56
|
+
* Generate contract source with parameter substitution
|
|
57
|
+
*/
|
|
58
|
+
static generateContract(templateName: string, params?: Record<string, any>): SubstitutionResult;
|
|
59
|
+
/**
|
|
60
|
+
* Perform parameter substitution in template source
|
|
61
|
+
*/
|
|
62
|
+
private static substituteParameters;
|
|
63
|
+
/**
|
|
64
|
+
* Format parameter value for code generation
|
|
65
|
+
*/
|
|
66
|
+
private static formatParameterValue;
|
|
67
|
+
/**
|
|
68
|
+
* Get template usage examples
|
|
69
|
+
*/
|
|
70
|
+
static getTemplateExample(templateName: string): string | null;
|
|
71
|
+
}
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Template Registry with Parameter Substitution
|
|
4
|
+
*
|
|
5
|
+
* Manages contract templates, validates parameters, and performs
|
|
6
|
+
* parameter substitution to generate deployable contract source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TemplateRegistry = void 0;
|
|
10
|
+
const TemplateValidator_1 = require("./TemplateValidator");
|
|
11
|
+
class TemplateRegistry {
|
|
12
|
+
/**
|
|
13
|
+
* Initialize the template registry with built-in templates
|
|
14
|
+
*/
|
|
15
|
+
static initialize() {
|
|
16
|
+
if (this.initialized)
|
|
17
|
+
return;
|
|
18
|
+
// Register Token template
|
|
19
|
+
this.registerTemplate({
|
|
20
|
+
name: 'Token',
|
|
21
|
+
schema: {
|
|
22
|
+
name: 'Token',
|
|
23
|
+
description: 'Standard token contract with ERC-20-like functionality',
|
|
24
|
+
version: '1.0.0',
|
|
25
|
+
author: 'Kynesys Labs',
|
|
26
|
+
parameters: [
|
|
27
|
+
{
|
|
28
|
+
name: 'TOKEN_NAME',
|
|
29
|
+
type: 'string',
|
|
30
|
+
required: true,
|
|
31
|
+
default: 'DemosToken',
|
|
32
|
+
pattern: /^[A-Za-z0-9\s]{1,32}$/,
|
|
33
|
+
description: 'The name of the token (e.g., "My Token")'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'TOKEN_SYMBOL',
|
|
37
|
+
type: 'string',
|
|
38
|
+
required: true,
|
|
39
|
+
default: 'DTK',
|
|
40
|
+
pattern: /^[A-Z]{1,8}$/,
|
|
41
|
+
description: 'The symbol of the token (e.g., "MTK")'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'TOTAL_SUPPLY',
|
|
45
|
+
type: 'number',
|
|
46
|
+
required: true,
|
|
47
|
+
default: 1000000,
|
|
48
|
+
min: 1,
|
|
49
|
+
max: 1000000000000,
|
|
50
|
+
description: 'Initial token supply'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'DECIMALS',
|
|
54
|
+
type: 'number',
|
|
55
|
+
required: false,
|
|
56
|
+
default: 18,
|
|
57
|
+
min: 0,
|
|
58
|
+
max: 18,
|
|
59
|
+
description: 'Number of decimal places for the token'
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
sourceFile: 'Token.ts.template'
|
|
64
|
+
});
|
|
65
|
+
// Register Storage template
|
|
66
|
+
this.registerTemplate({
|
|
67
|
+
name: 'Storage',
|
|
68
|
+
schema: {
|
|
69
|
+
name: 'Storage',
|
|
70
|
+
description: 'Key-value storage contract with access control',
|
|
71
|
+
version: '1.0.0',
|
|
72
|
+
author: 'Kynesys Labs',
|
|
73
|
+
parameters: [
|
|
74
|
+
{
|
|
75
|
+
name: 'IS_PUBLIC',
|
|
76
|
+
type: 'boolean',
|
|
77
|
+
required: false,
|
|
78
|
+
default: false,
|
|
79
|
+
description: 'Whether the storage allows public read access'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'MAX_KEYS',
|
|
83
|
+
type: 'number',
|
|
84
|
+
required: false,
|
|
85
|
+
default: 1000,
|
|
86
|
+
min: 1,
|
|
87
|
+
max: 10000,
|
|
88
|
+
description: 'Maximum number of keys that can be stored'
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
sourceFile: 'Storage.ts.template'
|
|
93
|
+
});
|
|
94
|
+
this.initialized = true;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Register a new template
|
|
98
|
+
*/
|
|
99
|
+
static registerTemplate(templateInfo) {
|
|
100
|
+
this.templates.set(templateInfo.name, templateInfo);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get all available template names
|
|
104
|
+
*/
|
|
105
|
+
static getAvailableTemplates() {
|
|
106
|
+
this.initialize();
|
|
107
|
+
return Array.from(this.templates.keys());
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get template information
|
|
111
|
+
*/
|
|
112
|
+
static getTemplate(name) {
|
|
113
|
+
this.initialize();
|
|
114
|
+
return this.templates.get(name) || null;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get template schema for validation
|
|
118
|
+
*/
|
|
119
|
+
static getTemplateSchema(name) {
|
|
120
|
+
const template = this.getTemplate(name);
|
|
121
|
+
return template ? template.schema : null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Load template source code
|
|
125
|
+
*/
|
|
126
|
+
static loadTemplateSource(template) {
|
|
127
|
+
if (template.source) {
|
|
128
|
+
return template.source;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
// In a real implementation, you'd load from the file system
|
|
132
|
+
// For now, we'll use the embedded source strings
|
|
133
|
+
// const templatePath = path.join(__dirname, template.sourceFile)
|
|
134
|
+
// Since we can't actually read files in this context,
|
|
135
|
+
// we'll return the source based on template name
|
|
136
|
+
return this.getEmbeddedTemplateSource(template.name);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
throw new Error(`Failed to load template source for ${template.name}: ${error.message}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get embedded template source (temporary implementation)
|
|
144
|
+
*/
|
|
145
|
+
static getEmbeddedTemplateSource(templateName) {
|
|
146
|
+
// In a real implementation, these would be loaded from .contract.ts files
|
|
147
|
+
const sources = {
|
|
148
|
+
'Token': `
|
|
149
|
+
class Token extends DemosContract {
|
|
150
|
+
constructor(
|
|
151
|
+
name: string = "{{TOKEN_NAME}}",
|
|
152
|
+
symbol: string = "{{TOKEN_SYMBOL}}",
|
|
153
|
+
totalSupply: number = {{TOTAL_SUPPLY}},
|
|
154
|
+
decimals: number = {{DECIMALS}}
|
|
155
|
+
) {
|
|
156
|
+
super()
|
|
157
|
+
this.state.set('name', name)
|
|
158
|
+
this.state.set('symbol', symbol)
|
|
159
|
+
this.state.set('decimals', decimals)
|
|
160
|
+
this.state.set('totalSupply', totalSupply)
|
|
161
|
+
this.state.set('balances', {})
|
|
162
|
+
this.state.set('allowances', {})
|
|
163
|
+
const creator = this.sender
|
|
164
|
+
const balances = this.state.get('balances')
|
|
165
|
+
balances[creator] = totalSupply
|
|
166
|
+
this.state.set('balances', balances)
|
|
167
|
+
this.emit('Transfer', { from: '0x0', to: creator, amount: totalSupply })
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
name(): string { return this.state.get('name') }
|
|
171
|
+
symbol(): string { return this.state.get('symbol') }
|
|
172
|
+
decimals(): number { return this.state.get('decimals') }
|
|
173
|
+
totalSupply(): number { return this.state.get('totalSupply') }
|
|
174
|
+
|
|
175
|
+
balanceOf(address: string): number {
|
|
176
|
+
const balances = this.state.get('balances')
|
|
177
|
+
return balances[address] || 0
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
transfer(to: string, amount: number): boolean {
|
|
181
|
+
const from = this.sender
|
|
182
|
+
return this._transfer(from, to, amount)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private _transfer(from: string, to: string, amount: number): boolean {
|
|
186
|
+
if (!to || to === '0x0') this.revert('Transfer to zero address')
|
|
187
|
+
if (amount <= 0) this.revert('Transfer amount must be positive')
|
|
188
|
+
|
|
189
|
+
const balances = this.state.get('balances')
|
|
190
|
+
const fromBalance = balances[from] || 0
|
|
191
|
+
if (fromBalance < amount) this.revert('Insufficient balance')
|
|
192
|
+
|
|
193
|
+
balances[from] = fromBalance - amount
|
|
194
|
+
balances[to] = (balances[to] || 0) + amount
|
|
195
|
+
this.state.set('balances', balances)
|
|
196
|
+
|
|
197
|
+
this.emit('Transfer', { from, to, amount })
|
|
198
|
+
return true
|
|
199
|
+
}
|
|
200
|
+
}`,
|
|
201
|
+
'Storage': `
|
|
202
|
+
class Storage extends DemosContract {
|
|
203
|
+
constructor(
|
|
204
|
+
isPublic: boolean = {{IS_PUBLIC}},
|
|
205
|
+
maxKeys: number = {{MAX_KEYS}}
|
|
206
|
+
) {
|
|
207
|
+
super()
|
|
208
|
+
this.state.set('owner', this.sender)
|
|
209
|
+
this.state.set('isPublic', isPublic)
|
|
210
|
+
this.state.set('maxKeys', maxKeys)
|
|
211
|
+
this.state.set('keyCount', 0)
|
|
212
|
+
this.state.set('data', {})
|
|
213
|
+
this.state.set('authorizedUsers', {})
|
|
214
|
+
|
|
215
|
+
const authorizedUsers = {}
|
|
216
|
+
authorizedUsers[this.sender] = true
|
|
217
|
+
this.state.set('authorizedUsers', authorizedUsers)
|
|
218
|
+
|
|
219
|
+
this.emit('StorageCreated', { owner: this.sender, isPublic, maxKeys })
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
store(key: string, value: any): boolean {
|
|
223
|
+
this._requireWriteAccess()
|
|
224
|
+
this._validateKey(key)
|
|
225
|
+
|
|
226
|
+
const data = this.state.get('data')
|
|
227
|
+
const isNewKey = !(key in data)
|
|
228
|
+
|
|
229
|
+
if (isNewKey) {
|
|
230
|
+
const currentKeyCount = this.state.get('keyCount')
|
|
231
|
+
const maxKeys = this.state.get('maxKeys')
|
|
232
|
+
if (currentKeyCount >= maxKeys) this.revert('Maximum key limit reached')
|
|
233
|
+
this.state.set('keyCount', currentKeyCount + 1)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
data[key] = { value, timestamp: this.blockHeight, author: this.sender }
|
|
237
|
+
this.state.set('data', data)
|
|
238
|
+
this.emit('ValueStored', { key, value, author: this.sender, isNewKey })
|
|
239
|
+
return true
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
retrieve(key: string): any {
|
|
243
|
+
this._requireReadAccess()
|
|
244
|
+
this._validateKey(key)
|
|
245
|
+
const data = this.state.get('data')
|
|
246
|
+
const entry = data[key]
|
|
247
|
+
if (!entry) return null
|
|
248
|
+
this.emit('ValueRetrieved', { key, value: entry.value, requester: this.sender })
|
|
249
|
+
return entry.value
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private _requireReadAccess(): void {
|
|
253
|
+
const isPublic = this.state.get('isPublic')
|
|
254
|
+
if (isPublic) return
|
|
255
|
+
const authorizedUsers = this.state.get('authorizedUsers')
|
|
256
|
+
if (authorizedUsers[this.sender] !== true) this.revert('Read access denied')
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private _requireWriteAccess(): void {
|
|
260
|
+
const authorizedUsers = this.state.get('authorizedUsers')
|
|
261
|
+
if (authorizedUsers[this.sender] !== true) this.revert('Write access denied')
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private _validateKey(key: string): void {
|
|
265
|
+
if (!key || typeof key !== 'string') this.revert('Invalid key: must be non-empty string')
|
|
266
|
+
if (key.length > 64) this.revert('Key too long: maximum 64 characters')
|
|
267
|
+
if (key.startsWith('_') || key.includes('\\0')) this.revert('Invalid key format')
|
|
268
|
+
}
|
|
269
|
+
}`
|
|
270
|
+
};
|
|
271
|
+
return sources[templateName] || '';
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Validate template parameters
|
|
275
|
+
*/
|
|
276
|
+
static validateParameters(templateName, params) {
|
|
277
|
+
this.initialize();
|
|
278
|
+
const template = this.getTemplate(templateName);
|
|
279
|
+
if (!template) {
|
|
280
|
+
return {
|
|
281
|
+
valid: false,
|
|
282
|
+
errors: [`Template '${templateName}' not found`],
|
|
283
|
+
warnings: [],
|
|
284
|
+
processedParams: {}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
return TemplateValidator_1.TemplateValidator.validate(template.schema, params);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Generate contract source with parameter substitution
|
|
291
|
+
*/
|
|
292
|
+
static generateContract(templateName, params = {}) {
|
|
293
|
+
this.initialize();
|
|
294
|
+
const template = this.getTemplate(templateName);
|
|
295
|
+
if (!template) {
|
|
296
|
+
return {
|
|
297
|
+
success: false,
|
|
298
|
+
errors: [`Template '${templateName}' not found`],
|
|
299
|
+
warnings: []
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// Validate parameters
|
|
303
|
+
const validation = this.validateParameters(templateName, params);
|
|
304
|
+
if (!validation.valid) {
|
|
305
|
+
return {
|
|
306
|
+
success: false,
|
|
307
|
+
errors: validation.errors,
|
|
308
|
+
warnings: validation.warnings
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
try {
|
|
312
|
+
// Load template source
|
|
313
|
+
const templateSource = this.loadTemplateSource(template);
|
|
314
|
+
// Perform parameter substitution
|
|
315
|
+
const substitutedSource = this.substituteParameters(templateSource, validation.processedParams);
|
|
316
|
+
return {
|
|
317
|
+
success: true,
|
|
318
|
+
source: substitutedSource,
|
|
319
|
+
errors: [],
|
|
320
|
+
warnings: validation.warnings
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
return {
|
|
325
|
+
success: false,
|
|
326
|
+
errors: [`Template generation failed: ${error.message}`],
|
|
327
|
+
warnings: validation.warnings
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Perform parameter substitution in template source
|
|
333
|
+
*/
|
|
334
|
+
static substituteParameters(source, params) {
|
|
335
|
+
let result = source;
|
|
336
|
+
// Replace each parameter placeholder
|
|
337
|
+
for (const [key, value] of Object.entries(params)) {
|
|
338
|
+
const placeholder = `{{${key}}}`;
|
|
339
|
+
const replacement = this.formatParameterValue(value);
|
|
340
|
+
// Replace all occurrences
|
|
341
|
+
result = result.replace(new RegExp(placeholder, 'g'), replacement);
|
|
342
|
+
}
|
|
343
|
+
// Check for unreplaced placeholders
|
|
344
|
+
const unreplacedMatches = result.match(/\{\{[^}]+\}\}/g);
|
|
345
|
+
if (unreplacedMatches) {
|
|
346
|
+
throw new Error(`Unreplaced template parameters: ${unreplacedMatches.join(', ')}`);
|
|
347
|
+
}
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Format parameter value for code generation
|
|
352
|
+
*/
|
|
353
|
+
static formatParameterValue(value) {
|
|
354
|
+
if (typeof value === 'string') {
|
|
355
|
+
return `"${value.replace(/"/g, '\\"')}"`; // Escape quotes
|
|
356
|
+
}
|
|
357
|
+
else if (typeof value === 'boolean') {
|
|
358
|
+
return value.toString();
|
|
359
|
+
}
|
|
360
|
+
else if (typeof value === 'number') {
|
|
361
|
+
return value.toString();
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
return JSON.stringify(value);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Get template usage examples
|
|
369
|
+
*/
|
|
370
|
+
static getTemplateExample(templateName) {
|
|
371
|
+
this.initialize();
|
|
372
|
+
const examples = {
|
|
373
|
+
'Token': `
|
|
374
|
+
// Deploy a custom token
|
|
375
|
+
const token = await demos.contracts.deployTemplate('Token', {
|
|
376
|
+
TOKEN_NAME: 'MyToken',
|
|
377
|
+
TOKEN_SYMBOL: 'MTK',
|
|
378
|
+
TOTAL_SUPPLY: 1000000,
|
|
379
|
+
DECIMALS: 18
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
// Interact with the token
|
|
383
|
+
const balance = await token.balanceOf('address')
|
|
384
|
+
await token.transfer('recipient', 100)
|
|
385
|
+
`,
|
|
386
|
+
'Storage': `
|
|
387
|
+
// Deploy a private storage contract
|
|
388
|
+
const storage = await demos.contracts.deployTemplate('Storage', {
|
|
389
|
+
IS_PUBLIC: false,
|
|
390
|
+
MAX_KEYS: 500
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
// Use the storage
|
|
394
|
+
await storage.store('myKey', 'myValue')
|
|
395
|
+
const value = await storage.retrieve('myKey')
|
|
396
|
+
`
|
|
397
|
+
};
|
|
398
|
+
return examples[templateName] || null;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
exports.TemplateRegistry = TemplateRegistry;
|
|
402
|
+
TemplateRegistry.templates = new Map();
|
|
403
|
+
TemplateRegistry.initialized = false;
|
|
404
|
+
//# sourceMappingURL=TemplateRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateRegistry.js","sourceRoot":"","sources":["../../../../src/contracts/templates/TemplateRegistry.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH,2DAAyF;AAgBzF,MAAa,gBAAgB;IAIzB;;OAEG;IACH,MAAM,CAAC,UAAU;QACb,IAAI,IAAI,CAAC,WAAW;YAAE,OAAM;QAE5B,0BAA0B;QAC1B,IAAI,CAAC,gBAAgB,CAAC;YAClB,IAAI,EAAE,OAAO;YACb,MAAM,EAAE;gBACJ,IAAI,EAAE,OAAO;gBACb,WAAW,EAAE,wDAAwD;gBACrE,OAAO,EAAE,OAAO;gBACh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CA8aC;AA7akB,0BAAS,GAA8B,IAAI,GAAG,EAAE,CAAA;AAChD,4BAAW,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template parameter validation system
|
|
3
|
+
*
|
|
4
|
+
* Validates template parameters before deployment to ensure
|
|
5
|
+
* safe and correct contract generation.
|
|
6
|
+
*/
|
|
7
|
+
export interface TemplateParameter {
|
|
8
|
+
name: string;
|
|
9
|
+
type: 'string' | 'number' | 'boolean' | 'address';
|
|
10
|
+
required: boolean;
|
|
11
|
+
default?: any;
|
|
12
|
+
min?: number;
|
|
13
|
+
max?: number;
|
|
14
|
+
pattern?: RegExp;
|
|
15
|
+
description: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TemplateSchema {
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
parameters: TemplateParameter[];
|
|
21
|
+
version: string;
|
|
22
|
+
author?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ValidationResult {
|
|
25
|
+
valid: boolean;
|
|
26
|
+
errors: string[];
|
|
27
|
+
warnings: string[];
|
|
28
|
+
processedParams: Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
export declare class TemplateValidator {
|
|
31
|
+
/**
|
|
32
|
+
* Validate parameters against a template schema
|
|
33
|
+
*/
|
|
34
|
+
static validate(schema: TemplateSchema, params?: Record<string, any>): ValidationResult;
|
|
35
|
+
/**
|
|
36
|
+
* Validate parameter type
|
|
37
|
+
*/
|
|
38
|
+
private static validateType;
|
|
39
|
+
/**
|
|
40
|
+
* Validate number range
|
|
41
|
+
*/
|
|
42
|
+
private static validateNumberRange;
|
|
43
|
+
/**
|
|
44
|
+
* Validate string pattern
|
|
45
|
+
*/
|
|
46
|
+
private static validatePattern;
|
|
47
|
+
/**
|
|
48
|
+
* Validate address format
|
|
49
|
+
*/
|
|
50
|
+
private static validateAddress;
|
|
51
|
+
/**
|
|
52
|
+
* Get human-readable validation summary
|
|
53
|
+
*/
|
|
54
|
+
static getValidationSummary(result: ValidationResult): string;
|
|
55
|
+
}
|