@beclab/olaresid 0.1.5 → 0.1.6
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/utils/crypto-utils.d.ts.map +1 -1
- package/dist/utils/crypto-utils.js +29 -4
- package/dist/utils/crypto-utils.js.map +1 -1
- package/examples/frontend-demo/.dockerignore +40 -0
- package/examples/frontend-demo/index.html +13 -0
- package/examples/frontend-demo/package-lock.json +5304 -0
- package/examples/frontend-demo/package.json +32 -0
- package/examples/frontend-demo/src/App.vue +1156 -0
- package/examples/frontend-demo/src/main.ts +5 -0
- package/examples/frontend-demo/src/style.css +323 -0
- package/examples/frontend-demo/tsconfig.json +24 -0
- package/examples/frontend-demo/webpack.config.js +86 -0
- package/package.json +1 -1
- package/src/utils/crypto-utils.ts +29 -4
- package/examples/quasar-demo/.eslintrc.js +0 -23
- package/examples/quasar-demo/.quasar/app.js +0 -43
- package/examples/quasar-demo/.quasar/client-entry.js +0 -38
- package/examples/quasar-demo/.quasar/client-prefetch.js +0 -130
- package/examples/quasar-demo/.quasar/quasar-user-options.js +0 -16
- package/examples/quasar-demo/README.md +0 -49
- package/examples/quasar-demo/index.html +0 -11
- package/examples/quasar-demo/package-lock.json +0 -6407
- package/examples/quasar-demo/package.json +0 -36
- package/examples/quasar-demo/quasar.config.js +0 -73
- package/examples/quasar-demo/src/App.vue +0 -13
- package/examples/quasar-demo/src/css/app.scss +0 -1
- package/examples/quasar-demo/src/layouts/MainLayout.vue +0 -21
- package/examples/quasar-demo/src/pages/IndexPage.vue +0 -905
- package/examples/quasar-demo/src/router/index.ts +0 -25
- package/examples/quasar-demo/src/router/routes.ts +0 -11
- package/examples/quasar-demo/tsconfig.json +0 -28
|
@@ -1,905 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<q-page class="flex flex-center">
|
|
3
|
-
<div class="q-pa-md">
|
|
4
|
-
<h3 class="text-h3 q-mb-md">OlaresID Demo</h3>
|
|
5
|
-
|
|
6
|
-
<q-card class="q-pa-md" style="min-width: 400px">
|
|
7
|
-
<q-separator />
|
|
8
|
-
|
|
9
|
-
<q-card-section>
|
|
10
|
-
<div class="text-h6 q-mb-md">MetaMask Connection</div>
|
|
11
|
-
|
|
12
|
-
<div v-if="currentNetwork" class="q-mb-md">
|
|
13
|
-
<q-chip
|
|
14
|
-
:color="
|
|
15
|
-
currentNetwork === 'Mainnet'
|
|
16
|
-
? 'orange'
|
|
17
|
-
: currentNetwork === 'Testnet'
|
|
18
|
-
? 'blue'
|
|
19
|
-
: 'red'
|
|
20
|
-
"
|
|
21
|
-
text-color="white"
|
|
22
|
-
:icon="
|
|
23
|
-
currentNetwork === 'Unsupported'
|
|
24
|
-
? 'warning'
|
|
25
|
-
: 'link'
|
|
26
|
-
"
|
|
27
|
-
>
|
|
28
|
-
{{ currentNetwork }} ({{ currentChainId }})
|
|
29
|
-
</q-chip>
|
|
30
|
-
<div
|
|
31
|
-
v-if="currentNetwork === 'Unsupported'"
|
|
32
|
-
class="text-caption text-red q-mt-sm"
|
|
33
|
-
>
|
|
34
|
-
Please switch to Optimism Mainnet or OP Sepolia
|
|
35
|
-
Testnet
|
|
36
|
-
</div>
|
|
37
|
-
</div>
|
|
38
|
-
|
|
39
|
-
<div v-if="!walletConnected">
|
|
40
|
-
<q-btn
|
|
41
|
-
color="primary"
|
|
42
|
-
label="Connect MetaMask"
|
|
43
|
-
icon="account_balance_wallet"
|
|
44
|
-
@click="connectMetaMask"
|
|
45
|
-
:loading="connecting"
|
|
46
|
-
/>
|
|
47
|
-
</div>
|
|
48
|
-
<div v-else>
|
|
49
|
-
<q-banner class="bg-green text-white q-mb-md" rounded>
|
|
50
|
-
<template v-slot:avatar>
|
|
51
|
-
<q-icon name="check_circle" />
|
|
52
|
-
</template>
|
|
53
|
-
Connected: {{ walletAddress }}
|
|
54
|
-
</q-banner>
|
|
55
|
-
<q-btn
|
|
56
|
-
flat
|
|
57
|
-
color="negative"
|
|
58
|
-
label="Disconnect"
|
|
59
|
-
@click="disconnectWallet"
|
|
60
|
-
/>
|
|
61
|
-
</div>
|
|
62
|
-
</q-card-section>
|
|
63
|
-
|
|
64
|
-
<q-separator />
|
|
65
|
-
|
|
66
|
-
<!-- Domain Context Demo -->
|
|
67
|
-
<q-card-section>
|
|
68
|
-
<div class="text-h6 q-mb-md">📋 Domain Context</div>
|
|
69
|
-
<q-input
|
|
70
|
-
v-model="domainName"
|
|
71
|
-
label="Domain Name"
|
|
72
|
-
placeholder="e.g., 1.com"
|
|
73
|
-
outlined
|
|
74
|
-
class="q-mb-md"
|
|
75
|
-
:disable="!walletConnected"
|
|
76
|
-
/>
|
|
77
|
-
<div class="q-gutter-sm">
|
|
78
|
-
<q-btn
|
|
79
|
-
color="primary"
|
|
80
|
-
label="Get Meta Info"
|
|
81
|
-
@click="getMetaInfo"
|
|
82
|
-
:loading="loading.metaInfo"
|
|
83
|
-
:disable="!domainName || !walletConnected"
|
|
84
|
-
/>
|
|
85
|
-
<q-btn
|
|
86
|
-
color="primary"
|
|
87
|
-
label="Get Owner"
|
|
88
|
-
@click="getOwner"
|
|
89
|
-
:loading="loading.owner"
|
|
90
|
-
:disable="!domainName || !walletConnected"
|
|
91
|
-
/>
|
|
92
|
-
<q-btn
|
|
93
|
-
color="secondary"
|
|
94
|
-
label="Is Owner?"
|
|
95
|
-
@click="checkIsOwner"
|
|
96
|
-
:loading="loading.isOwner"
|
|
97
|
-
:disable="!domainName || !walletConnected"
|
|
98
|
-
/>
|
|
99
|
-
</div>
|
|
100
|
-
<div v-if="results.domainContext" class="q-mt-md">
|
|
101
|
-
<q-banner class="bg-blue-1">
|
|
102
|
-
<pre class="text-caption">{{
|
|
103
|
-
results.domainContext
|
|
104
|
-
}}</pre>
|
|
105
|
-
</q-banner>
|
|
106
|
-
</div>
|
|
107
|
-
</q-card-section>
|
|
108
|
-
|
|
109
|
-
<q-separator />
|
|
110
|
-
|
|
111
|
-
<!-- IP Demo -->
|
|
112
|
-
<q-card-section>
|
|
113
|
-
<div class="text-h6 q-mb-md">🌐 IP Address Management</div>
|
|
114
|
-
<q-input
|
|
115
|
-
v-model="ipAddress"
|
|
116
|
-
label="IP Address"
|
|
117
|
-
placeholder="e.g., 192.168.1.100"
|
|
118
|
-
outlined
|
|
119
|
-
class="q-mb-md"
|
|
120
|
-
:disable="!walletConnected"
|
|
121
|
-
/>
|
|
122
|
-
<div class="q-gutter-sm q-mb-md">
|
|
123
|
-
<q-btn
|
|
124
|
-
color="green"
|
|
125
|
-
label="Set IP"
|
|
126
|
-
@click="setIP"
|
|
127
|
-
:loading="loading.setIP"
|
|
128
|
-
:disable="
|
|
129
|
-
!domainName || !ipAddress || !walletConnected
|
|
130
|
-
"
|
|
131
|
-
/>
|
|
132
|
-
<q-btn
|
|
133
|
-
color="primary"
|
|
134
|
-
label="Get IP"
|
|
135
|
-
@click="getIP"
|
|
136
|
-
:loading="loading.getIP"
|
|
137
|
-
:disable="!domainName || !walletConnected"
|
|
138
|
-
/>
|
|
139
|
-
<q-btn
|
|
140
|
-
color="negative"
|
|
141
|
-
label="Remove IP"
|
|
142
|
-
@click="removeIP"
|
|
143
|
-
:loading="loading.removeIP"
|
|
144
|
-
:disable="!domainName || !walletConnected"
|
|
145
|
-
/>
|
|
146
|
-
</div>
|
|
147
|
-
<div class="q-gutter-sm">
|
|
148
|
-
<q-btn
|
|
149
|
-
flat
|
|
150
|
-
color="blue"
|
|
151
|
-
label="IPv4 to Bytes4"
|
|
152
|
-
@click="convertIPv4ToBytes4"
|
|
153
|
-
:disable="!ipAddress"
|
|
154
|
-
/>
|
|
155
|
-
<q-btn
|
|
156
|
-
flat
|
|
157
|
-
color="blue"
|
|
158
|
-
label="Bytes4 to IPv4"
|
|
159
|
-
@click="convertBytes4ToIPv4"
|
|
160
|
-
:disable="!ipAddress"
|
|
161
|
-
/>
|
|
162
|
-
</div>
|
|
163
|
-
<div v-if="results.ip" class="q-mt-md">
|
|
164
|
-
<q-banner class="bg-green-1">
|
|
165
|
-
<pre class="text-caption">{{ results.ip }}</pre>
|
|
166
|
-
</q-banner>
|
|
167
|
-
</div>
|
|
168
|
-
</q-card-section>
|
|
169
|
-
|
|
170
|
-
<q-separator />
|
|
171
|
-
|
|
172
|
-
<!-- RSA Key Pair Demo -->
|
|
173
|
-
<q-card-section>
|
|
174
|
-
<div class="text-h6 q-mb-md">🔐 RSA Key Management</div>
|
|
175
|
-
<div class="q-gutter-sm q-mb-md">
|
|
176
|
-
<q-btn
|
|
177
|
-
color="purple"
|
|
178
|
-
label="Generate RSA Key Pair"
|
|
179
|
-
@click="generateRSAKeyPair"
|
|
180
|
-
:loading="loading.generateRSA"
|
|
181
|
-
/>
|
|
182
|
-
</div>
|
|
183
|
-
<div v-if="rsaKeyPair" class="q-mb-md">
|
|
184
|
-
<q-banner class="bg-purple-1">
|
|
185
|
-
<div class="text-caption">
|
|
186
|
-
<strong>Public Key (PEM):</strong>
|
|
187
|
-
<pre
|
|
188
|
-
>{{
|
|
189
|
-
rsaKeyPair.publicKey.substring(0, 100)
|
|
190
|
-
}}...</pre
|
|
191
|
-
>
|
|
192
|
-
<strong>Private Key (PEM):</strong>
|
|
193
|
-
<pre
|
|
194
|
-
>{{
|
|
195
|
-
rsaKeyPair.privateKey.substring(0, 100)
|
|
196
|
-
}}...</pre
|
|
197
|
-
>
|
|
198
|
-
</div>
|
|
199
|
-
</q-banner>
|
|
200
|
-
</div>
|
|
201
|
-
<div class="q-gutter-sm q-mb-md">
|
|
202
|
-
<q-btn
|
|
203
|
-
color="green"
|
|
204
|
-
label="Set RSA Public Key"
|
|
205
|
-
@click="setRSAPublicKey"
|
|
206
|
-
:loading="loading.setRSA"
|
|
207
|
-
:disable="
|
|
208
|
-
!domainName || !rsaKeyPair || !walletConnected
|
|
209
|
-
"
|
|
210
|
-
/>
|
|
211
|
-
<q-btn
|
|
212
|
-
color="primary"
|
|
213
|
-
label="Get RSA Public Key"
|
|
214
|
-
@click="getRSAPublicKey"
|
|
215
|
-
:loading="loading.getRSA"
|
|
216
|
-
:disable="!domainName || !walletConnected"
|
|
217
|
-
/>
|
|
218
|
-
<q-btn
|
|
219
|
-
color="negative"
|
|
220
|
-
label="Remove RSA Key"
|
|
221
|
-
@click="removeRSAPublicKey"
|
|
222
|
-
:loading="loading.removeRSA"
|
|
223
|
-
:disable="!domainName || !walletConnected"
|
|
224
|
-
/>
|
|
225
|
-
</div>
|
|
226
|
-
<div class="q-gutter-sm">
|
|
227
|
-
<q-btn
|
|
228
|
-
flat
|
|
229
|
-
color="blue"
|
|
230
|
-
label="PEM to DER"
|
|
231
|
-
@click="convertPEMToDER"
|
|
232
|
-
:disable="!rsaKeyPair"
|
|
233
|
-
/>
|
|
234
|
-
<q-btn
|
|
235
|
-
flat
|
|
236
|
-
color="blue"
|
|
237
|
-
label="DER to PEM"
|
|
238
|
-
@click="convertDERToPEM"
|
|
239
|
-
:disable="!rsaKeyPair"
|
|
240
|
-
/>
|
|
241
|
-
</div>
|
|
242
|
-
<div v-if="results.rsa" class="q-mt-md">
|
|
243
|
-
<q-banner class="bg-purple-1">
|
|
244
|
-
<pre class="text-caption">{{ results.rsa }}</pre>
|
|
245
|
-
</q-banner>
|
|
246
|
-
</div>
|
|
247
|
-
</q-card-section>
|
|
248
|
-
</q-card>
|
|
249
|
-
</div>
|
|
250
|
-
</q-page>
|
|
251
|
-
</template>
|
|
252
|
-
|
|
253
|
-
<script lang="ts">
|
|
254
|
-
import { defineComponent, ref, onMounted, reactive } from 'vue';
|
|
255
|
-
import { useQuasar } from 'quasar';
|
|
256
|
-
import * as OlaresIDModule from '@beclab/olaresid';
|
|
257
|
-
import { ethers } from 'ethers';
|
|
258
|
-
|
|
259
|
-
const OlaresID = (OlaresIDModule as any).default || OlaresIDModule;
|
|
260
|
-
const { createRsaKeyPair, pemToDer, derToPem, ipv4ToBytes4, bytes4ToIpv4 } =
|
|
261
|
-
OlaresIDModule as any;
|
|
262
|
-
|
|
263
|
-
declare global {
|
|
264
|
-
interface Window {
|
|
265
|
-
ethereum?: any;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export default defineComponent({
|
|
270
|
-
name: 'IndexPage',
|
|
271
|
-
setup() {
|
|
272
|
-
const $q = useQuasar();
|
|
273
|
-
const olaresIdInfo = ref('');
|
|
274
|
-
const domainName = ref('1.com');
|
|
275
|
-
const ipAddress = ref('192.168.1.100');
|
|
276
|
-
const rsaKeyPair = ref<any>(null);
|
|
277
|
-
|
|
278
|
-
// Loading states
|
|
279
|
-
const loading = reactive({
|
|
280
|
-
metaInfo: false,
|
|
281
|
-
owner: false,
|
|
282
|
-
isOwner: false,
|
|
283
|
-
setIP: false,
|
|
284
|
-
getIP: false,
|
|
285
|
-
removeIP: false,
|
|
286
|
-
generateRSA: false,
|
|
287
|
-
setRSA: false,
|
|
288
|
-
getRSA: false,
|
|
289
|
-
removeRSA: false
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
// Results
|
|
293
|
-
const results = reactive({
|
|
294
|
-
domainContext: '',
|
|
295
|
-
ip: '',
|
|
296
|
-
rsa: ''
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// MetaMask state
|
|
300
|
-
const walletConnected = ref(false);
|
|
301
|
-
const walletAddress = ref('');
|
|
302
|
-
const connecting = ref(false);
|
|
303
|
-
const currentNetwork = ref('');
|
|
304
|
-
const currentChainId = ref('');
|
|
305
|
-
|
|
306
|
-
// Initialize OlaresID - will be set based on network
|
|
307
|
-
let olaresId = OlaresID.createTestnet(); // default to testnet
|
|
308
|
-
|
|
309
|
-
onMounted(async () => {
|
|
310
|
-
// Check if already connected and detect network
|
|
311
|
-
await checkMetaMaskConnection();
|
|
312
|
-
|
|
313
|
-
// Listen for network changes
|
|
314
|
-
if (typeof window.ethereum !== 'undefined') {
|
|
315
|
-
window.ethereum.on('chainChanged', handleChainChanged);
|
|
316
|
-
window.ethereum.on('accountsChanged', handleAccountsChanged);
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
const handleChainChanged = async (chainId: string) => {
|
|
321
|
-
console.log('Chain changed to:', chainId);
|
|
322
|
-
currentChainId.value = chainId;
|
|
323
|
-
await reinitializeOlaresId();
|
|
324
|
-
|
|
325
|
-
$q.notify({
|
|
326
|
-
type: 'info',
|
|
327
|
-
message: 'Network changed',
|
|
328
|
-
caption: `Switched to ${currentNetwork.value}`
|
|
329
|
-
});
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
const handleAccountsChanged = async (accounts: string[]) => {
|
|
333
|
-
console.log('Accounts changed:', accounts);
|
|
334
|
-
if (accounts.length === 0) {
|
|
335
|
-
disconnectWallet();
|
|
336
|
-
} else if (accounts[0] !== walletAddress.value) {
|
|
337
|
-
walletAddress.value = accounts[0];
|
|
338
|
-
await setSignerToOlaresId();
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
const getNetworkName = (chainId: string): string => {
|
|
343
|
-
const networks: Record<string, string> = {
|
|
344
|
-
'0xa': 'Optimism Mainnet',
|
|
345
|
-
'0xaa37dc': 'OP Sepolia Testnet'
|
|
346
|
-
};
|
|
347
|
-
return networks[chainId] || `Unsupported Network (${chainId})`;
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
const isMainnet = (chainId: string): boolean => {
|
|
351
|
-
// Only Optimism Mainnet
|
|
352
|
-
return chainId === '0xa';
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
const isSupportedNetwork = (chainId: string): boolean => {
|
|
356
|
-
// Only support Optimism Mainnet and OP Sepolia Testnet
|
|
357
|
-
return chainId === '0xa' || chainId === '0xaa37dc';
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
const reinitializeOlaresId = async () => {
|
|
361
|
-
// Check if network is supported
|
|
362
|
-
if (!isSupportedNetwork(currentChainId.value)) {
|
|
363
|
-
currentNetwork.value = 'Unsupported';
|
|
364
|
-
olaresIdInfo.value = `⚠️ Unsupported Network!
|
|
365
|
-
Chain ID: ${currentChainId.value}
|
|
366
|
-
Chain Name: ${getNetworkName(currentChainId.value)}
|
|
367
|
-
|
|
368
|
-
Please switch to:
|
|
369
|
-
• Optimism Mainnet (0xa)
|
|
370
|
-
• OP Sepolia Testnet (0xaa37dc)`;
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const isMainnetNetwork = isMainnet(currentChainId.value);
|
|
375
|
-
|
|
376
|
-
// Reinitialize OlaresID based on network
|
|
377
|
-
if (isMainnetNetwork) {
|
|
378
|
-
olaresId = OlaresID.createMainnet();
|
|
379
|
-
currentNetwork.value = 'Mainnet';
|
|
380
|
-
console.log('Reinitialized OlaresID for Optimism Mainnet');
|
|
381
|
-
} else {
|
|
382
|
-
olaresId = OlaresID.createTestnet();
|
|
383
|
-
currentNetwork.value = 'Testnet';
|
|
384
|
-
console.log('Reinitialized OlaresID for OP Sepolia Testnet');
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Update info display
|
|
388
|
-
olaresIdInfo.value = `OlaresID instance created!
|
|
389
|
-
Network: ${currentNetwork.value}
|
|
390
|
-
Chain ID: ${currentChainId.value}
|
|
391
|
-
Chain Name: ${getNetworkName(currentChainId.value)}
|
|
392
|
-
Type: ${typeof olaresId}`;
|
|
393
|
-
|
|
394
|
-
// If wallet is connected, set signer again
|
|
395
|
-
if (walletConnected.value) {
|
|
396
|
-
await setSignerToOlaresId();
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
const checkMetaMaskConnection = async () => {
|
|
401
|
-
if (typeof window.ethereum !== 'undefined') {
|
|
402
|
-
try {
|
|
403
|
-
// Get current chain ID
|
|
404
|
-
const chainId = await window.ethereum.request({
|
|
405
|
-
method: 'eth_chainId'
|
|
406
|
-
});
|
|
407
|
-
currentChainId.value = chainId;
|
|
408
|
-
console.log('Current chain ID:', chainId);
|
|
409
|
-
|
|
410
|
-
// Reinitialize OlaresID based on detected network
|
|
411
|
-
await reinitializeOlaresId();
|
|
412
|
-
|
|
413
|
-
// Check if accounts are already connected
|
|
414
|
-
const accounts = await window.ethereum.request({
|
|
415
|
-
method: 'eth_accounts'
|
|
416
|
-
});
|
|
417
|
-
if (accounts.length > 0) {
|
|
418
|
-
walletAddress.value = accounts[0];
|
|
419
|
-
walletConnected.value = true;
|
|
420
|
-
await setSignerToOlaresId();
|
|
421
|
-
}
|
|
422
|
-
} catch (err) {
|
|
423
|
-
console.error('Error checking MetaMask connection:', err);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
const connectMetaMask = async () => {
|
|
429
|
-
if (typeof window.ethereum === 'undefined') {
|
|
430
|
-
$q.notify({
|
|
431
|
-
type: 'negative',
|
|
432
|
-
message: 'MetaMask not detected',
|
|
433
|
-
caption: 'Please install MetaMask extension'
|
|
434
|
-
});
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
connecting.value = true;
|
|
439
|
-
|
|
440
|
-
try {
|
|
441
|
-
// Get current chain ID first
|
|
442
|
-
const chainId = await window.ethereum.request({
|
|
443
|
-
method: 'eth_chainId'
|
|
444
|
-
});
|
|
445
|
-
currentChainId.value = chainId;
|
|
446
|
-
console.log(
|
|
447
|
-
'Connecting on chain:',
|
|
448
|
-
chainId,
|
|
449
|
-
getNetworkName(chainId)
|
|
450
|
-
);
|
|
451
|
-
|
|
452
|
-
// Check if network is supported
|
|
453
|
-
if (!isSupportedNetwork(chainId)) {
|
|
454
|
-
$q.notify({
|
|
455
|
-
type: 'negative',
|
|
456
|
-
message: 'Unsupported Network',
|
|
457
|
-
caption:
|
|
458
|
-
'Please switch to Optimism Mainnet or OP Sepolia Testnet',
|
|
459
|
-
timeout: 5000
|
|
460
|
-
});
|
|
461
|
-
await reinitializeOlaresId();
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// Reinitialize OlaresID based on network
|
|
466
|
-
await reinitializeOlaresId();
|
|
467
|
-
|
|
468
|
-
// Request account access
|
|
469
|
-
const accounts = await window.ethereum.request({
|
|
470
|
-
method: 'eth_requestAccounts'
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
if (accounts.length > 0) {
|
|
474
|
-
walletAddress.value = accounts[0];
|
|
475
|
-
walletConnected.value = true;
|
|
476
|
-
|
|
477
|
-
// Set signer to OlaresID
|
|
478
|
-
await setSignerToOlaresId();
|
|
479
|
-
|
|
480
|
-
$q.notify({
|
|
481
|
-
type: 'positive',
|
|
482
|
-
message: 'MetaMask connected successfully!',
|
|
483
|
-
caption: `${getNetworkName(
|
|
484
|
-
chainId
|
|
485
|
-
)} - ${walletAddress.value.substring(
|
|
486
|
-
0,
|
|
487
|
-
6
|
|
488
|
-
)}...${walletAddress.value.substring(38)}`
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
console.log(
|
|
492
|
-
'Connected wallet address:',
|
|
493
|
-
walletAddress.value
|
|
494
|
-
);
|
|
495
|
-
console.log(
|
|
496
|
-
'Using OlaresID network:',
|
|
497
|
-
currentNetwork.value
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
} catch (err: any) {
|
|
501
|
-
console.error('MetaMask connection error:', err);
|
|
502
|
-
$q.notify({
|
|
503
|
-
type: 'negative',
|
|
504
|
-
message: 'Failed to connect MetaMask',
|
|
505
|
-
caption: err.message
|
|
506
|
-
});
|
|
507
|
-
} finally {
|
|
508
|
-
connecting.value = false;
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
const setSignerToOlaresId = async () => {
|
|
513
|
-
try {
|
|
514
|
-
// Create ethers provider from MetaMask
|
|
515
|
-
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
516
|
-
const signer = await provider.getSigner();
|
|
517
|
-
|
|
518
|
-
// Set signer to OlaresID instance
|
|
519
|
-
olaresId.setSigner(signer);
|
|
520
|
-
|
|
521
|
-
console.log('Signer set to OlaresID:', signer);
|
|
522
|
-
console.log('OlaresID now has signer:', olaresId.signer);
|
|
523
|
-
|
|
524
|
-
// Update info display
|
|
525
|
-
olaresIdInfo.value = `OlaresID instance with MetaMask signer!
|
|
526
|
-
Network: ${currentNetwork.value}
|
|
527
|
-
Chain ID: ${currentChainId.value}
|
|
528
|
-
Chain Name: ${getNetworkName(currentChainId.value)}
|
|
529
|
-
Type: ${typeof olaresId}
|
|
530
|
-
Signer Address: ${await signer.getAddress()}
|
|
531
|
-
Has Signer: ${olaresId.signer !== undefined}`;
|
|
532
|
-
} catch (err) {
|
|
533
|
-
console.error('Error setting signer to OlaresID:', err);
|
|
534
|
-
throw err;
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
const disconnectWallet = () => {
|
|
539
|
-
walletConnected.value = false;
|
|
540
|
-
walletAddress.value = '';
|
|
541
|
-
|
|
542
|
-
// Clear signer from OlaresID
|
|
543
|
-
olaresId.clearSigner();
|
|
544
|
-
|
|
545
|
-
olaresIdInfo.value = `OlaresID instance created!
|
|
546
|
-
Network: ${currentNetwork.value}
|
|
547
|
-
Chain ID: ${currentChainId.value}
|
|
548
|
-
Chain Name: ${getNetworkName(currentChainId.value)}
|
|
549
|
-
Type: ${typeof olaresId}
|
|
550
|
-
Has Signer: ${olaresId.signer !== undefined}`;
|
|
551
|
-
|
|
552
|
-
$q.notify({
|
|
553
|
-
type: 'info',
|
|
554
|
-
message: 'Wallet disconnected'
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
console.log('Wallet disconnected, signer cleared from OlaresID');
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
// ===== Domain Context Methods =====
|
|
561
|
-
const getMetaInfo = async () => {
|
|
562
|
-
loading.metaInfo = true;
|
|
563
|
-
results.domainContext = '';
|
|
564
|
-
try {
|
|
565
|
-
const domain = olaresId.domain(domainName.value);
|
|
566
|
-
const metaInfo = await domain.getMetaInfo();
|
|
567
|
-
results.domainContext = `Meta Info:
|
|
568
|
-
ID: ${metaInfo.id}
|
|
569
|
-
Name: ${metaInfo.name}
|
|
570
|
-
DID: ${metaInfo.did}
|
|
571
|
-
Note: ${metaInfo.note || 'N/A'}
|
|
572
|
-
Allow Subdomain: ${metaInfo.allowSubdomain}`;
|
|
573
|
-
$q.notify({
|
|
574
|
-
type: 'positive',
|
|
575
|
-
message: 'Meta info retrieved!'
|
|
576
|
-
});
|
|
577
|
-
} catch (err: any) {
|
|
578
|
-
$q.notify({
|
|
579
|
-
type: 'negative',
|
|
580
|
-
message: 'Failed',
|
|
581
|
-
caption: err.message
|
|
582
|
-
});
|
|
583
|
-
} finally {
|
|
584
|
-
loading.metaInfo = false;
|
|
585
|
-
}
|
|
586
|
-
};
|
|
587
|
-
|
|
588
|
-
const getOwner = async () => {
|
|
589
|
-
loading.owner = true;
|
|
590
|
-
results.domainContext = '';
|
|
591
|
-
try {
|
|
592
|
-
const domain = olaresId.domain(domainName.value);
|
|
593
|
-
const owner = await domain.getOwner();
|
|
594
|
-
results.domainContext = `Owner Address:\n${owner}`;
|
|
595
|
-
$q.notify({ type: 'positive', message: 'Owner retrieved!' });
|
|
596
|
-
} catch (err: any) {
|
|
597
|
-
$q.notify({
|
|
598
|
-
type: 'negative',
|
|
599
|
-
message: 'Failed',
|
|
600
|
-
caption: err.message
|
|
601
|
-
});
|
|
602
|
-
} finally {
|
|
603
|
-
loading.owner = false;
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
|
|
607
|
-
const checkIsOwner = async () => {
|
|
608
|
-
loading.isOwner = true;
|
|
609
|
-
results.domainContext = '';
|
|
610
|
-
try {
|
|
611
|
-
const domain = olaresId.domain(domainName.value);
|
|
612
|
-
const isOwner = await domain.isOwner();
|
|
613
|
-
results.domainContext = `Is Owner: ${
|
|
614
|
-
isOwner ? 'Yes ✅' : 'No ❌'
|
|
615
|
-
}`;
|
|
616
|
-
$q.notify({
|
|
617
|
-
type: isOwner ? 'positive' : 'info',
|
|
618
|
-
message: isOwner
|
|
619
|
-
? 'You are the owner!'
|
|
620
|
-
: 'You are not the owner'
|
|
621
|
-
});
|
|
622
|
-
} catch (err: any) {
|
|
623
|
-
$q.notify({
|
|
624
|
-
type: 'negative',
|
|
625
|
-
message: 'Failed',
|
|
626
|
-
caption: err.message
|
|
627
|
-
});
|
|
628
|
-
} finally {
|
|
629
|
-
loading.isOwner = false;
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
// ===== IP Methods =====
|
|
634
|
-
const setIP = async () => {
|
|
635
|
-
loading.setIP = true;
|
|
636
|
-
results.ip = '';
|
|
637
|
-
try {
|
|
638
|
-
const domain = olaresId.domain(domainName.value);
|
|
639
|
-
const result = await domain.setIP(ipAddress.value);
|
|
640
|
-
if (result.success) {
|
|
641
|
-
results.ip = `IP Set Successfully!
|
|
642
|
-
Transaction Hash: ${result.transactionHash}
|
|
643
|
-
Gas Used: ${result.gasUsed?.toString()}`;
|
|
644
|
-
$q.notify({
|
|
645
|
-
type: 'positive',
|
|
646
|
-
message: 'IP address set!',
|
|
647
|
-
timeout: 3000
|
|
648
|
-
});
|
|
649
|
-
} else {
|
|
650
|
-
throw new Error(result.error || 'Failed to set IP');
|
|
651
|
-
}
|
|
652
|
-
} catch (err: any) {
|
|
653
|
-
$q.notify({
|
|
654
|
-
type: 'negative',
|
|
655
|
-
message: 'Failed',
|
|
656
|
-
caption: err.message
|
|
657
|
-
});
|
|
658
|
-
} finally {
|
|
659
|
-
loading.setIP = false;
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
const getIP = async () => {
|
|
664
|
-
loading.getIP = true;
|
|
665
|
-
results.ip = '';
|
|
666
|
-
try {
|
|
667
|
-
const domain = olaresId.domain(domainName.value);
|
|
668
|
-
const ip = await domain.getIP();
|
|
669
|
-
results.ip = ip ? `IP Address: ${ip}` : 'No IP address set';
|
|
670
|
-
$q.notify({ type: 'positive', message: 'IP retrieved!' });
|
|
671
|
-
} catch (err: any) {
|
|
672
|
-
$q.notify({
|
|
673
|
-
type: 'negative',
|
|
674
|
-
message: 'Failed',
|
|
675
|
-
caption: err.message
|
|
676
|
-
});
|
|
677
|
-
} finally {
|
|
678
|
-
loading.getIP = false;
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
|
|
682
|
-
const removeIP = async () => {
|
|
683
|
-
loading.removeIP = true;
|
|
684
|
-
results.ip = '';
|
|
685
|
-
try {
|
|
686
|
-
const domain = olaresId.domain(domainName.value);
|
|
687
|
-
const result = await domain.removeIP();
|
|
688
|
-
if (result.success) {
|
|
689
|
-
results.ip = `IP Removed Successfully!
|
|
690
|
-
Transaction Hash: ${result.transactionHash}`;
|
|
691
|
-
$q.notify({
|
|
692
|
-
type: 'positive',
|
|
693
|
-
message: 'IP address removed!'
|
|
694
|
-
});
|
|
695
|
-
} else {
|
|
696
|
-
throw new Error(result.error || 'Failed to remove IP');
|
|
697
|
-
}
|
|
698
|
-
} catch (err: any) {
|
|
699
|
-
$q.notify({
|
|
700
|
-
type: 'negative',
|
|
701
|
-
message: 'Failed',
|
|
702
|
-
caption: err.message
|
|
703
|
-
});
|
|
704
|
-
} finally {
|
|
705
|
-
loading.removeIP = false;
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
const convertIPv4ToBytes4 = () => {
|
|
710
|
-
try {
|
|
711
|
-
const bytes4 = ipv4ToBytes4(ipAddress.value);
|
|
712
|
-
results.ip = `IPv4 to Bytes4:
|
|
713
|
-
${ipAddress.value} → ${bytes4}`;
|
|
714
|
-
$q.notify({ type: 'positive', message: 'Converted!' });
|
|
715
|
-
} catch (err: any) {
|
|
716
|
-
$q.notify({ type: 'negative', message: 'Invalid IP address' });
|
|
717
|
-
}
|
|
718
|
-
};
|
|
719
|
-
|
|
720
|
-
const convertBytes4ToIPv4 = () => {
|
|
721
|
-
try {
|
|
722
|
-
const ip = bytes4ToIpv4(ipAddress.value);
|
|
723
|
-
results.ip = `Bytes4 to IPv4:
|
|
724
|
-
${ipAddress.value} → ${ip}`;
|
|
725
|
-
$q.notify({ type: 'positive', message: 'Converted!' });
|
|
726
|
-
} catch (err: any) {
|
|
727
|
-
$q.notify({
|
|
728
|
-
type: 'negative',
|
|
729
|
-
message: 'Invalid bytes4 format'
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
// ===== RSA Methods =====
|
|
735
|
-
const generateRSAKeyPair = async () => {
|
|
736
|
-
loading.generateRSA = true;
|
|
737
|
-
results.rsa = '';
|
|
738
|
-
try {
|
|
739
|
-
const keyPair = await createRsaKeyPair();
|
|
740
|
-
rsaKeyPair.value = {
|
|
741
|
-
publicKey: keyPair.rsaPublicKey,
|
|
742
|
-
privateKey: keyPair.rsaPrivateKey
|
|
743
|
-
};
|
|
744
|
-
results.rsa = 'RSA Key Pair Generated Successfully!';
|
|
745
|
-
$q.notify({
|
|
746
|
-
type: 'positive',
|
|
747
|
-
message: 'RSA key pair generated!'
|
|
748
|
-
});
|
|
749
|
-
} catch (err: any) {
|
|
750
|
-
$q.notify({
|
|
751
|
-
type: 'negative',
|
|
752
|
-
message: 'Failed',
|
|
753
|
-
caption: err.message
|
|
754
|
-
});
|
|
755
|
-
} finally {
|
|
756
|
-
loading.generateRSA = false;
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
|
|
760
|
-
const setRSAPublicKey = async () => {
|
|
761
|
-
loading.setRSA = true;
|
|
762
|
-
results.rsa = '';
|
|
763
|
-
try {
|
|
764
|
-
const domain = olaresId.domain(domainName.value);
|
|
765
|
-
const result = await domain.setRSAPublicKey(
|
|
766
|
-
rsaKeyPair.value.publicKey
|
|
767
|
-
);
|
|
768
|
-
if (result.success) {
|
|
769
|
-
results.rsa = `RSA Public Key Set Successfully!
|
|
770
|
-
Transaction Hash: ${result.transactionHash}
|
|
771
|
-
Gas Used: ${result.gasUsed?.toString()}`;
|
|
772
|
-
$q.notify({
|
|
773
|
-
type: 'positive',
|
|
774
|
-
message: 'RSA public key set!',
|
|
775
|
-
timeout: 3000
|
|
776
|
-
});
|
|
777
|
-
} else {
|
|
778
|
-
throw new Error(result.error || 'Failed to set RSA key');
|
|
779
|
-
}
|
|
780
|
-
} catch (err: any) {
|
|
781
|
-
$q.notify({
|
|
782
|
-
type: 'negative',
|
|
783
|
-
message: 'Failed',
|
|
784
|
-
caption: err.message
|
|
785
|
-
});
|
|
786
|
-
} finally {
|
|
787
|
-
loading.setRSA = false;
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
|
|
791
|
-
const getRSAPublicKey = async () => {
|
|
792
|
-
loading.getRSA = true;
|
|
793
|
-
results.rsa = '';
|
|
794
|
-
try {
|
|
795
|
-
const domain = olaresId.domain(domainName.value);
|
|
796
|
-
const key = await domain.getRSAPublicKey();
|
|
797
|
-
results.rsa = key
|
|
798
|
-
? `RSA Public Key (PEM):\n${key}`
|
|
799
|
-
: 'No RSA public key set';
|
|
800
|
-
$q.notify({ type: 'positive', message: 'RSA key retrieved!' });
|
|
801
|
-
} catch (err: any) {
|
|
802
|
-
$q.notify({
|
|
803
|
-
type: 'negative',
|
|
804
|
-
message: 'Failed',
|
|
805
|
-
caption: err.message
|
|
806
|
-
});
|
|
807
|
-
} finally {
|
|
808
|
-
loading.getRSA = false;
|
|
809
|
-
}
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
const removeRSAPublicKey = async () => {
|
|
813
|
-
loading.removeRSA = true;
|
|
814
|
-
results.rsa = '';
|
|
815
|
-
try {
|
|
816
|
-
const domain = olaresId.domain(domainName.value);
|
|
817
|
-
const result = await domain.removeRSAPublicKey();
|
|
818
|
-
if (result.success) {
|
|
819
|
-
results.rsa = `RSA Public Key Removed Successfully!
|
|
820
|
-
Transaction Hash: ${result.transactionHash}`;
|
|
821
|
-
$q.notify({
|
|
822
|
-
type: 'positive',
|
|
823
|
-
message: 'RSA key removed!'
|
|
824
|
-
});
|
|
825
|
-
} else {
|
|
826
|
-
throw new Error(result.error || 'Failed to remove RSA key');
|
|
827
|
-
}
|
|
828
|
-
} catch (err: any) {
|
|
829
|
-
$q.notify({
|
|
830
|
-
type: 'negative',
|
|
831
|
-
message: 'Failed',
|
|
832
|
-
caption: err.message
|
|
833
|
-
});
|
|
834
|
-
} finally {
|
|
835
|
-
loading.removeRSA = false;
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
|
|
839
|
-
const convertPEMToDER = () => {
|
|
840
|
-
try {
|
|
841
|
-
const der = pemToDer(rsaKeyPair.value.publicKey);
|
|
842
|
-
results.rsa = `PEM to DER:
|
|
843
|
-
${der.substring(0, 100)}...`;
|
|
844
|
-
$q.notify({ type: 'positive', message: 'Converted to DER!' });
|
|
845
|
-
} catch (err: any) {
|
|
846
|
-
$q.notify({ type: 'negative', message: 'Conversion failed' });
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
const convertDERToPEM = () => {
|
|
851
|
-
try {
|
|
852
|
-
const der = pemToDer(rsaKeyPair.value.publicKey);
|
|
853
|
-
const pem = derToPem(der);
|
|
854
|
-
results.rsa = `DER to PEM:
|
|
855
|
-
${pem}`;
|
|
856
|
-
$q.notify({ type: 'positive', message: 'Converted to PEM!' });
|
|
857
|
-
} catch (err: any) {
|
|
858
|
-
$q.notify({ type: 'negative', message: 'Conversion failed' });
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
|
|
862
|
-
return {
|
|
863
|
-
olaresIdInfo,
|
|
864
|
-
domainName,
|
|
865
|
-
ipAddress,
|
|
866
|
-
rsaKeyPair,
|
|
867
|
-
loading,
|
|
868
|
-
results,
|
|
869
|
-
walletConnected,
|
|
870
|
-
walletAddress,
|
|
871
|
-
connecting,
|
|
872
|
-
currentNetwork,
|
|
873
|
-
currentChainId,
|
|
874
|
-
connectMetaMask,
|
|
875
|
-
disconnectWallet,
|
|
876
|
-
// Domain Context methods
|
|
877
|
-
getMetaInfo,
|
|
878
|
-
getOwner,
|
|
879
|
-
checkIsOwner,
|
|
880
|
-
// IP methods
|
|
881
|
-
setIP,
|
|
882
|
-
getIP,
|
|
883
|
-
removeIP,
|
|
884
|
-
convertIPv4ToBytes4,
|
|
885
|
-
convertBytes4ToIPv4,
|
|
886
|
-
// RSA methods
|
|
887
|
-
generateRSAKeyPair,
|
|
888
|
-
setRSAPublicKey,
|
|
889
|
-
getRSAPublicKey,
|
|
890
|
-
removeRSAPublicKey,
|
|
891
|
-
convertPEMToDER,
|
|
892
|
-
convertDERToPEM
|
|
893
|
-
};
|
|
894
|
-
}
|
|
895
|
-
});
|
|
896
|
-
</script>
|
|
897
|
-
|
|
898
|
-
<style scoped>
|
|
899
|
-
pre {
|
|
900
|
-
background: #f5f5f5;
|
|
901
|
-
padding: 12px;
|
|
902
|
-
border-radius: 4px;
|
|
903
|
-
overflow-x: auto;
|
|
904
|
-
}
|
|
905
|
-
</style>
|