Skip to content

Commit f732b3f

Browse files
committed
Expose EncryptedSecreKey (NIP49)
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 21551f6 commit f732b3f

File tree

13 files changed

+1451
-44
lines changed

13 files changed

+1451
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
### Added
3333

3434
* Add `Events::as_vec` ([Yuki Kishimoto])
35+
* Expose `EncryptedSecreKey` ([Yuki Kishimoto])
3536

3637
### Fixed
3738

lib/nostr_sdk.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export 'src/rust/api/protocol/event/unsigned.dart';
1010
export 'src/rust/api/protocol/key.dart';
1111
export 'src/rust/api/protocol/key/public_key.dart';
1212
export 'src/rust/api/protocol/key/secret_key.dart';
13+
export 'src/rust/api/protocol/nips/nip49.dart';
1314
export 'src/rust/api/protocol/nips/nip59.dart';
1415
export 'src/rust/api/protocol/filter.dart';
1516
export 'src/rust/api/protocol/signer.dart';

lib/src/rust/api/protocol/key/secret_key.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
55

66
import '../../../frb_generated.dart';
7+
import '../nips/nip49.dart';
78
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
89

9-
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `from`
10+
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `deref`, `from`
1011
// These functions have error during generation (see debug logs or enable `stop_on_error: true` for more details): `to_secret_bytes`
1112

1213
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_SecretKey>>
1314
abstract class SecretKey implements RustOpaqueInterface {
15+
/// Encrypt secret key
16+
///
17+
/// By default, `LOG_N` is set to `16` and `EncryptedSecretKeySecurity` to `Unknown`.
18+
/// To use custom values, check `EncryptedSecretKey`.
19+
EncryptedSecretKey encrypt({required String password});
20+
1421
/// Parse from bytes
1522
static SecretKey fromSlice({required List<int> secretKey}) =>
1623
NostrSdk.instance.api
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// This file is automatically generated, so please do not edit it.
2+
// Generated by `flutter_rust_bridge`@ 2.0.0.
3+
4+
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
5+
6+
import '../../../frb_generated.dart';
7+
import '../key/secret_key.dart';
8+
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
9+
10+
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `from`, `from`, `from`, `from`
11+
12+
// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<_EncryptedSecretKey>>
13+
abstract class EncryptedSecretKey implements RustOpaqueInterface {
14+
/// Decrypt secret key
15+
SecretKey decrypt({required String password});
16+
17+
/// Parse from bech32
18+
static EncryptedSecretKey fromBech32({required String bech32}) => NostrSdk
19+
.instance.api
20+
.crateApiProtocolNipsNip49EncryptedSecretKeyFromBech32(bech32: bech32);
21+
22+
/// Get encrypted secret key security
23+
EncryptedSecretKeySecurity keySecurity();
24+
25+
/// Encrypt secret key
26+
factory EncryptedSecretKey(
27+
{required SecretKey secretKey,
28+
required String password,
29+
required int logN,
30+
required EncryptedSecretKeySecurity keySecurity}) =>
31+
NostrSdk.instance.api.crateApiProtocolNipsNip49EncryptedSecretKeyNew(
32+
secretKey: secretKey,
33+
password: password,
34+
logN: logN,
35+
keySecurity: keySecurity);
36+
37+
/// Serialize to bech32
38+
String toBech32();
39+
40+
/// Get encrypted secret key version
41+
EncryptedSecretKeyVersion version();
42+
}
43+
44+
/// Key security
45+
enum EncryptedSecretKeySecurity {
46+
/// The key has been known to have been handled insecurely (stored unencrypted, cut and paste unencrypted, etc)
47+
weak,
48+
49+
/// The key has NOT been known to have been handled insecurely (stored encrypted, cut and paste encrypted, etc)
50+
medium,
51+
52+
/// The client does not track this data
53+
unknown,
54+
;
55+
}
56+
57+
/// Encrypted Secret Key version (NIP49)
58+
enum EncryptedSecretKeyVersion {
59+
v2,
60+
;
61+
}

0 commit comments

Comments
 (0)