Skip to content

Commit

Permalink
add more rust funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
ljttl3q04t committed Dec 16, 2024
1 parent af1e2cc commit 4ce6fe0
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct BiometricSetupView: View {
switch screenType {
case .createWallet(let seedPhrase, let nickName):
let seedPhrase = seedPhrase.joined(separator: " ")
let wallet = createWallet(phrase: seedPhrase, password: MinWalletConstant.passDefaultForFaceID, networkEnv: AppSetting.NetworkEnv.mainnet.rawValue)
let wallet = createWallet(phrase: seedPhrase, password: MinWalletConstant.passDefaultForFaceID, networkEnv: AppSetting.NetworkEnv.mainnet.rawValue, walletName: "FIX ME")
userInfo.saveWalletInfo(seedPhrase: seedPhrase, nickName: nickName, walletAddress: wallet.address)
appSetting.isLogin = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct CreateNewPasswordView: View {
appSetting.authenticationType = .password
appSetting.isLogin = true
let seedPhrase = seedPhrase.joined(separator: " ")
let wallet = createWallet(phrase: seedPhrase, password: password, networkEnv: AppSetting.NetworkEnv.mainnet.rawValue)
let wallet = createWallet(phrase: seedPhrase, password: password, networkEnv: AppSetting.NetworkEnv.mainnet.rawValue, walletName: "FIX ME")
userInfo.saveWalletInfo(seedPhrase: seedPhrase, nickName: nickName, walletAddress: wallet.address)

navigator.push(.createWallet(.createNewWalletSuccess))
Expand Down
1 change: 1 addition & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bindings
target
ios
.idea
4 changes: 3 additions & 1 deletion rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ hex = "0.4.3"
rand = "0.8.5"
uniffi = { version = "0.28.2", features = ["cli"] }
cryptoxide = "0.4.4"
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.133"

[build-dependencies]
uniffi = { version = "0.28.2", features = ["build"] }
Expand Down
68 changes: 64 additions & 4 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ let phrase = genPhrase(wordCount: 12)

---

#### `createWallet(phrase: String, password: String, networkEnv: String) -> MinWallet`
#### `createWallet(phrase: String, password: String, networkEnv: String, walletName: String) -> MinWallet`
Creates a wallet based on the provided mnemonic phrase, password, and network environment.

- **Parameters**:
- `phrase`: The mnemonic phrase used to derive the wallet.
- `password`: A user-defined password for encrypting the wallet's private key.
- `networkEnv`: The network environment for the wallet (e.g., `"mainnet"` or `"preprod"`).
- `walletName`: The Name of Wallet.
- **Returns**:
- A `MinWallet` object containing wallet details.

Expand All @@ -44,7 +45,8 @@ Creates a wallet based on the provided mnemonic phrase, password, and network en
let wallet = createWallet(
phrase: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
password: "secure_password",
networkEnv: "preprod"
networkEnv: "preprod",
walletName: "My MinWallet"
)
```

Expand All @@ -60,6 +62,62 @@ Signs a raw transaction using the provided wallet.
- `txRaw`: The raw transaction string to be signed.
- **Returns**:
- A signed transaction `String`.
---

#### `change_password(wallet: MinWallet, current_password: String, new_password: String) -> MinWallet`
Changes the password of a given wallet.

- **Parameters**:
- `wallet`: A `MinWallet` object containing wallet details.
- `current_password`: The current password used to decrypt the wallet.
- `new_password`: The new password to set for the wallet.
- **Returns**:
- An updated `MinWallet` object with the new password applied.

---

#### `verify_password(wallet: MinWallet, password: String) -> boolean`
Verifies whether the provided password matches the wallet's password.

- **Parameters**:
- `wallet`: A `MinWallet` object containing wallet details.
- `password`: The password to be verified.
- **Returns**:
- A `boolean` indicating whether the password is correct (`true`) or incorrect (`false`).

---

#### `export_wallet(wallet: MinWallet, password: String, network_env: String) -> String`
Exports the wallet's data as a string for backup or transfer purposes.

- **Parameters**:
- `wallet`: A `MinWallet` object containing wallet details.
- `password`: The password used to encrypt the exported wallet data.
- `network_env`: The network environment for which the wallet data is exported (e.g., `mainnet` or `testnet`).
- **Returns**:
- A `String` containing the encrypted wallet data.

---

#### `import_wallet(data: String, password: String, wallet_name: String) -> MinWallet`
Imports a wallet from encrypted data.

- **Parameters**:
- `data`: The encrypted wallet data as a string.
- `password`: The password to decrypt the wallet data.
- `wallet_name`: The name to assign to the imported wallet.
- **Returns**:
- A `MinWallet` object representing the imported wallet.

---

#### `get_wallet_name_from_export_wallet(data: String) -> String`
Retrieves the wallet name from exported wallet data.

- **Parameters**:
- `data`: The exported wallet data as a string.
- **Returns**:
- A `String` containing the wallet name.

#### Example:
```swift
Expand All @@ -75,22 +133,24 @@ let signedTx = signTx(

### Types

#### `MinWallet`
### `MinWallet`
A dictionary-like object containing details of a wallet.

- **Fields**:
- `address` (`String`): The wallet's address.
- `networkId` (`UInt32`): The ID of the network the wallet belongs to (mainnet: 764824073, preprod: 1).
- `accountIndex` (`UInt32`): The account index within the wallet.
- `encryptedKey` (`UInt32`): The wallet's encrypted private key.
- `walletName` (`String`): the wallet's name.

#### Example:
```swift
let wallet = MinWallet(
address: "addr_test1...",
networkId: 1,
accountIndex: 0,
encryptedKey: "<encrypted_data>"
encryptedKey: "<encrypted_data>",
walletName: "My MinWallet"
)
```

Expand Down
Loading

0 comments on commit 4ce6fe0

Please sign in to comment.