zano_web3 4.7.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -165,6 +165,94 @@ export interface Wallet {
|
|
|
165
165
|
```
|
|
166
166
|
|
|
167
167
|
|
|
168
|
+
## Server-Side Validator
|
|
169
|
+
|
|
170
|
+
The server-side validator function, `validateWallet`, is used to validate wallet authentication data using the Zano RPC API. It supports authentication using either an alias or a public key.
|
|
171
|
+
|
|
172
|
+
### Usage
|
|
173
|
+
|
|
174
|
+
The function `validateWallet` accepts a `rpcUrl` for the Zano node and an `AuthData` object containing the authentication details.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import validateWallet from './validateWallet';
|
|
178
|
+
|
|
179
|
+
const authData = {
|
|
180
|
+
address: 'wallet_address',
|
|
181
|
+
signature: 'signed_message',
|
|
182
|
+
message: 'original_message',
|
|
183
|
+
alias: 'user_alias' // or pkey: 'public_key'
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const rpcUrl = 'https://zano-node.example.com';
|
|
187
|
+
|
|
188
|
+
validateWallet(rpcUrl, authData)
|
|
189
|
+
.then(valid => {
|
|
190
|
+
if (valid) {
|
|
191
|
+
console.log('Wallet is valid');
|
|
192
|
+
} else {
|
|
193
|
+
console.log('Invalid wallet data');
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### AuthData Types
|
|
199
|
+
|
|
200
|
+
The `AuthData` type is a union of `AliasAuth` and `PkeyAuth` interfaces:
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
interface BaseAuthData {
|
|
204
|
+
address: string;
|
|
205
|
+
signature: string;
|
|
206
|
+
message: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface AliasAuth extends BaseAuthData {
|
|
210
|
+
alias: string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
interface PkeyAuth extends BaseAuthData {
|
|
214
|
+
pkey: string;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
type AuthData = AliasAuth | PkeyAuth;
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Internal Validation Logic
|
|
221
|
+
|
|
222
|
+
The `validateWallet` function internally uses the Zano RPC method `validate_signature` to verify the authenticity of the provided signature against the message. If an alias is provided, it also checks that the alias resolves to the correct wallet address.
|
|
223
|
+
|
|
224
|
+
### Functions
|
|
225
|
+
|
|
226
|
+
#### `validateWallet(rpcUrl: string, authData: AuthData)`
|
|
227
|
+
|
|
228
|
+
- `rpcUrl`: The URL of the Zano RPC node.
|
|
229
|
+
- `authData`: The authentication data, which includes the address, signature, message, and optionally alias or public key.
|
|
230
|
+
|
|
231
|
+
Returns `true` if the wallet data is valid, otherwise returns `false`.
|
|
232
|
+
|
|
233
|
+
#### Example
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
const authData = {
|
|
237
|
+
address: 'wallet_address',
|
|
238
|
+
signature: 'signed_message',
|
|
239
|
+
message: 'original_message',
|
|
240
|
+
alias: 'user_alias' // or pkey: 'public_key'
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const rpcUrl = 'https://zano-node.example.com';
|
|
244
|
+
|
|
245
|
+
validateWallet(rpcUrl, authData)
|
|
246
|
+
.then(valid => {
|
|
247
|
+
if (valid) {
|
|
248
|
+
console.log('Wallet is valid');
|
|
249
|
+
} else {
|
|
250
|
+
console.log('Invalid wallet data');
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
|
|
168
256
|
## Requirements
|
|
169
257
|
|
|
170
258
|
- ZanoWallet browser extension must be installed.
|