fix: some typos and format

This commit is contained in:
gzuuus
2025-07-18 10:17:22 +02:00
parent e0409ce99d
commit ffc3ac1c8b
25 changed files with 385 additions and 423 deletions

View File

@@ -11,9 +11,9 @@ One of the key design features of the `@contextvm/sdk` is its modularity, which
While the [`PrivateKeySigner`](/contextvm-docs/signer/private-key-signer) is a common choice for most applications, there are cases where you may need to use a different approach:
- **Security is paramount**: You need to keep private keys isolated from the main application logic, for example, in a hardware security module (HSM) or a secure enclave.
- **Interacting with external wallets**: Your application needs to request signatures from a user's wallet, such as a browser extension (e.g., Alby, Noster) or a mobile wallet.
- **Complex key management**: Your application uses a more complex key management architecture that doesn't involve direct access to raw private keys.
- **Security is paramount**: You need to keep private keys isolated from the main application logic, for example, in a hardware security module (HSM) or a secure enclave.
- **Interacting with external wallets**: Your application needs to request signatures from a user's wallet, such as a browser extension (e.g., Alby, Noster) or a mobile wallet.
- **Complex key management**: Your application uses a more complex key management architecture that doesn't involve direct access to raw private keys.
## Implementing the `NostrSigner` Interface
@@ -26,8 +26,8 @@ A common use case for a custom signer is in a web application that needs to inte
Here is how you could implement a `NostrSigner` that wraps the `window.nostr` object:
```typescript
import { NostrSigner } from '@ctxvm/sdk/core';
import { UnsignedEvent, NostrEvent } from 'nostr-tools';
import { NostrSigner } from "@ctxvm/sdk/core";
import { UnsignedEvent, NostrEvent } from "nostr-tools";
// Define the NIP-07 window.nostr interface for type-safety
declare global {
@@ -46,31 +46,31 @@ declare global {
class Nip07Signer implements NostrSigner {
constructor() {
if (!window.nostr) {
throw new Error('NIP-07 compatible browser extension not found.');
throw new Error("NIP-07 compatible browser extension not found.");
}
}
async getPublicKey(): Promise<string> {
if (!window.nostr) throw new Error('window.nostr not found.');
if (!window.nostr) throw new Error("window.nostr not found.");
return await window.nostr.getPublicKey();
}
async signEvent(event: UnsignedEvent): Promise<NostrEvent> {
if (!window.nostr) throw new Error('window.nostr not found.');
if (!window.nostr) throw new Error("window.nostr not found.");
return await window.nostr.signEvent(event);
}
nip44 = {
encrypt: async (pubkey: string, plaintext: string): Promise<string> => {
if (!window.nostr?.nip44) {
throw new Error('The extension does not support NIP-44 encryption.');
throw new Error("The extension does not support NIP-44 encryption.");
}
return await window.nostr.nip44.encrypt(pubkey, plaintext);
},
decrypt: async (pubkey: string, ciphertext: string): Promise<string> => {
if (!window.nostr?.nip44) {
throw new Error('The extension does not support NIP-44 decryption.');
throw new Error("The extension does not support NIP-44 decryption.");
}
return await window.nostr.nip44.decrypt(pubkey, ciphertext);
},
@@ -90,4 +90,4 @@ Once your custom signer class is created, you can instantiate it and pass it to
## Next Steps
With the `Signer` component covered, let's move on to the **[Relay](/contextvm-docs/relay/simple-relay-pool)** component, which handles the connection and management of Nostr relays.
With the `Signer` component covered, let's move on to the **[Relay](/contextvm-docs/relay/simple-relay-pool)** component, which handles the connection and management of Nostr relays.

View File

@@ -13,9 +13,9 @@ The primary purpose of the `NostrSigner` is to abstract the process of event sig
This design offers several key benefits:
- **Security**: Private keys can be managed in secure environments (e.g., web extensions, hardware wallets, dedicated signing services) without exposing them to the application logic.
- **Flexibility**: Developers can easily swap out the default signer with a custom implementation that meets their specific needs.
- **Modularity**: The signing logic is decoupled from the communication logic, leading to a cleaner, more maintainable codebase.
- **Security**: Private keys can be managed in secure environments (e.g., web extensions, hardware wallets, dedicated signing services) without exposing them to the application logic.
- **Flexibility**: Developers can easily swap out the default signer with a custom implementation that meets their specific needs.
- **Modularity**: The signing logic is decoupled from the communication logic, leading to a cleaner, more maintainable codebase.
## Interface Definition
@@ -40,10 +40,10 @@ export interface NostrSigner {
}
```
- `getPublicKey()`: Asynchronously returns the public key corresponding to the signer's private key.
- `signEvent(event)`: Takes an unsigned Nostr event, signs it, and returns the signature.
- `nip04`: (Deprecated) Provides NIP-04 encryption support.
- `nip44`: Provides NIP-44 encryption support.
- `getPublicKey()`: Asynchronously returns the public key corresponding to the signer's private key.
- `signEvent(event)`: Takes an unsigned Nostr event, signs it, and returns the signature.
- `nip04`: (Deprecated) Provides NIP-04 encryption support.
- `nip44`: Provides NIP-44 encryption support.
Any class that implements this interface can be used as a signer throughout the SDK.
@@ -51,10 +51,10 @@ Any class that implements this interface can be used as a signer throughout the
The SDK provides a default implementation for common use cases and allows for custom implementations for advanced scenarios.
- **[PrivateKeySigner](/contextvm-docs/signer/private-key-signer)**: The default implementation, which takes a raw private key string and performs signing operations locally.
- **[Custom Signer Development](/contextvm-docs/signer/custom-signer-development)**: For creating custom signers that integrate with key management systems, such as hardware wallets or remote signing services.
- **[PrivateKeySigner](/contextvm-docs/signer/private-key-signer)**: The default implementation, which takes a raw private key string and performs signing operations locally.
- **[Custom Signer Development](/contextvm-docs/signer/custom-signer-development)**: For creating custom signers that integrate with key management systems, such as hardware wallets or remote signing services.
## Next Steps
- Learn about the default implementation: **[PrivateKeySigner](/contextvm-docs/signer/private-key-signer)**
- Learn how to create your own: **[Custom Signer Development](/contextvm-docs/signer/custom-signer-development)**
- Learn about the default implementation: **[PrivateKeySigner](/contextvm-docs/signer/private-key-signer)**
- Learn how to create your own: **[Custom Signer Development](/contextvm-docs/signer/custom-signer-development)**

View File

@@ -11,25 +11,25 @@ The `PrivateKeySigner` is the default implementation of the [`NostrSigner`](/con
The `PrivateKeySigner` is designed for scenarios where the private key is readily available in the application's environment. It handles all the necessary cryptographic operations locally, including:
- Deriving the corresponding public key.
- Signing Nostr events.
- Encrypting and decrypting messages using NIP-44.
- Deriving the corresponding public key.
- Signing Nostr events.
- Encrypting and decrypting messages using NIP-44.
## `constructor(privateKey: string)`
The constructor takes a single argument:
- **`privateKey`**: A hexadecimal string representing the 32-byte Nostr private key.
- **`privateKey`**: A hexadecimal string representing the 32-byte Nostr private key.
When instantiated, the `PrivateKeySigner` will immediately convert the hex string into a `Uint8Array` and derive the public key, which is then cached for future calls to `getPublicKey()`.
## Usage Example
```typescript
import { PrivateKeySigner } from '@ctxvm/sdk/signer';
import { PrivateKeySigner } from "@ctxvm/sdk/signer";
// Replace with a securely stored private key
const privateKeyHex = 'your-32-byte-private-key-in-hex';
const privateKeyHex = "your-32-byte-private-key-in-hex";
const signer = new PrivateKeySigner(privateKeyHex);
@@ -56,8 +56,8 @@ Takes an unsigned Nostr event, signs it using the private key, and returns a pro
The `PrivateKeySigner` also provides a `nip44` object that implements NIP-44 encryption and decryption. This is used internally by the transports when encryption is enabled, and it allows the `decryptMessage` function to work seamlessly with this signer.
- `encrypt(pubkey, plaintext)`: Encrypts a plaintext message for a given recipient public key.
- `decrypt(pubkey, ciphertext)`: Decrypts a ciphertext message received from a given sender public key.
- `encrypt(pubkey, plaintext)`: Encrypts a plaintext message for a given recipient public key.
- `decrypt(pubkey, ciphertext)`: Decrypts a ciphertext message received from a given sender public key.
## Security Considerations
@@ -67,4 +67,4 @@ For applications requiring a higher level of security, consider creating a custo
## Next Steps
- Learn how to build a custom signer: **[Custom Signer Development](/contextvm-docs/signer/custom-signer-development)**
- Learn how to build a custom signer: **[Custom Signer Development](/contextvm-docs/signer/custom-signer-development)**