@phantom/crypto 0.1.1 → 1.0.0-beta.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.
Files changed (2) hide show
  1. package/README.md +114 -0
  2. package/package.json +2 -1
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @phantom/crypto
2
+
3
+ Cryptographic utilities for Phantom SDK, providing Ed25519 key generation, key pair management, and digital signing functionality.
4
+
5
+ ## Features
6
+
7
+ - **Ed25519 Key Pair Generation**: Generate cryptographically secure key pairs
8
+ - **Key Pair Recovery**: Recreate key pairs from existing secret keys
9
+ - **Digital Signing**: Sign data using Ed25519 with detached signatures
10
+ - **Base58 Encoding**: All keys are encoded in base58 format for compatibility
11
+ - **Cross-platform**: Works in both Node.js and browser environments
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @phantom/crypto
17
+ # or
18
+ yarn add @phantom/crypto
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### Generate a New Key Pair
24
+
25
+ ```typescript
26
+ import { generateKeyPair } from "@phantom/crypto";
27
+
28
+ const keyPair = generateKeyPair();
29
+ console.log("Public Key:", keyPair.publicKey);
30
+ console.log("Secret Key:", keyPair.secretKey);
31
+ ```
32
+
33
+ ### Create Key Pair from Existing Secret Key
34
+
35
+ ```typescript
36
+ import { createKeyPairFromSecret } from "@phantom/crypto";
37
+
38
+ const existingSecretKey = "your-base58-encoded-secret-key";
39
+ const keyPair = createKeyPairFromSecret(existingSecretKey);
40
+ console.log("Recovered Public Key:", keyPair.publicKey);
41
+ ```
42
+
43
+ ### Sign Data
44
+
45
+ ```typescript
46
+ import { signWithSecret } from "@phantom/crypto";
47
+
48
+ const secretKey = "your-base58-encoded-secret-key";
49
+ const message = "Hello, world!";
50
+
51
+ const signature = signWithSecret(secretKey, message);
52
+ console.log("Signature:", signature);
53
+ ```
54
+
55
+ ## API Reference
56
+
57
+ ### Types
58
+
59
+ #### `Keypair`
60
+
61
+ ```typescript
62
+ interface Keypair {
63
+ publicKey: string; // Base58-encoded public key
64
+ secretKey: string; // Base58-encoded secret key
65
+ }
66
+ ```
67
+
68
+ ### Functions
69
+
70
+ #### `generateKeyPair(): Keypair`
71
+
72
+ Generates a new Ed25519 key pair with cryptographically secure random keys.
73
+
74
+ **Returns:** A `Keypair` object with base58-encoded public and secret keys.
75
+
76
+ #### `createKeyPairFromSecret(b58PrivateKey: string): Keypair`
77
+
78
+ Reconstructs a key pair from an existing base58-encoded secret key.
79
+
80
+ **Parameters:**
81
+
82
+ - `b58PrivateKey`: Base58-encoded private key string
83
+
84
+ **Returns:** A `Keypair` object with the corresponding public key derived from the secret key.
85
+
86
+ #### `signWithSecret(secretKey: string | Uint8Array, data: string | Uint8Array | Buffer): Uint8Array`
87
+
88
+ Signs data using Ed25519 with a secret key, producing a detached signature.
89
+
90
+ **Parameters:**
91
+
92
+ - `secretKey`: Base58-encoded secret key string or raw Uint8Array
93
+ - `data`: Data to sign (accepts string, Uint8Array, or Buffer)
94
+
95
+ **Returns:** Raw signature as Uint8Array
96
+
97
+ ## Security Notes
98
+
99
+ - Always keep secret keys secure and never expose them in client-side code
100
+ - Use cryptographically secure random number generation (provided by TweetNaCl)
101
+ - Ed25519 provides strong security with 128-bit security level
102
+ - Signatures are deterministic but secure against forgery
103
+
104
+ ## Dependencies
105
+
106
+ This package uses:
107
+
108
+ - **TweetNaCl**: Cryptographic library for Ed25519 operations
109
+ - **bs58**: Base58 encoding/decoding
110
+ - **buffer**: Buffer polyfill for cross-platform compatibility
111
+
112
+ ## License
113
+
114
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/crypto",
3
- "version": "0.1.1",
3
+ "version": "1.0.0-beta.0",
4
4
  "description": "Cryptographic utilities for Phantom SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -24,6 +24,7 @@
24
24
  "test": "jest",
25
25
  "test:watch": "jest --watch",
26
26
  "lint": "tsc --noEmit && eslint --cache . --ext .ts",
27
+ "check-types": "tsc --noEmit",
27
28
  "prettier": "prettier --write \"src/**/*.{ts}\""
28
29
  },
29
30
  "dependencies": {