@nockbox/iris-wasm 0.2.0-alpha.3 → 0.2.0-alpha.4

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 CHANGED
@@ -100,16 +100,16 @@ http://localhost:8000/crates/iris-wasm/examples/grpc-web-demo.html
100
100
  ```javascript
101
101
  import init, {
102
102
  GrpcClient,
103
+ PrivateKey,
103
104
  deriveMasterKeyFromMnemonic,
104
- WasmTxBuilder,
105
- WasmNote,
106
- WasmVersion,
107
- WasmName,
108
- WasmDigest,
109
- WasmSpendCondition,
110
- WasmPkh,
111
- WasmLockPrimitive,
112
- WasmLockTim
105
+ txEngineSettingsV1Default,
106
+ TxBuilder,
107
+ Note,
108
+ Digest,
109
+ SpendCondition,
110
+ Pkh,
111
+ LockPrimitive,
112
+ LockTim
113
113
  } from './pkg/iris_wasm.js';
114
114
 
115
115
  // Initialize the WASM module
@@ -119,13 +119,13 @@ await init();
119
119
  const client = new GrpcClient('http://localhost:8080');
120
120
 
121
121
  // Get balance by wallet address
122
- const balance = await client.get_balance_by_address(
122
+ const balance = await client.getBalanceByAddress(
123
123
  '6psXufjYNRxffRx72w8FF9b5MYg8TEmWq2nEFkqYm51yfqsnkJu8XqX'
124
124
  );
125
125
  console.log('Balance:', balance);
126
126
 
127
127
  // Get balance by first name (note hash)
128
- const balanceByName = await client.get_balance_by_first_name(
128
+ const balanceByName = await client.getBalanceByFirstName(
129
129
  '2H7WHTE9dFXiGgx4J432DsCLuMovNkokfcnCGRg7utWGM9h13PgQvsH'
130
130
  );
131
131
  console.log('Balance by name:', balanceByName);
@@ -138,39 +138,40 @@ console.log('Balance by name:', balanceByName);
138
138
  const mnemonic = "dice domain inspire horse time...";
139
139
  const masterKey = deriveMasterKeyFromMnemonic(mnemonic, "");
140
140
 
141
- // Create notes from balance query
142
- const notes = balance.notes.map(entry => new WasmNote(
143
- WasmVersion.V1(),
144
- entry.note.noteVersion.v1.originPage.value,
145
- new WasmName(entry.name.first, entry.name.last),
146
- new WasmDigest(entry.note.noteVersion.v1.noteData.hash),
147
- entry.note.noteVersion.v1.assets.value
148
- ));
141
+ // Use one available note from the balance query
142
+ const note = Note.fromProtobuf(balance.notes[0].note);
149
143
 
150
144
  // Create spend condition
151
- const pubkeyHash = new WasmDigest("your_pubkey_hash_here");
152
- const spendCondition = new WasmSpendCondition([
153
- WasmLockPrimitive.newPkh(WasmPkh.single(pubkeyHash)),
154
- WasmLockPrimitive.newTim(WasmLockTim.coinbase())
145
+ const pubkeyHash = new Digest("your_pubkey_hash_here");
146
+ const spendCondition = new SpendCondition([
147
+ LockPrimitive.newPkh(Pkh.single(pubkeyHash)),
148
+ LockPrimitive.newTim(LockTim.coinbase())
155
149
  ]);
156
150
 
151
+ const settings = txEngineSettingsV1Default();
152
+ // Or use txEngineSettingsV1BythosDefault() when targeting Bythos defaults.
153
+
157
154
  // Build transaction
158
- const builder = WasmTxBuilder.newSimple(
159
- notes,
160
- spendCondition,
161
- new WasmDigest("recipient_address"),
155
+ const builder = new TxBuilder(settings);
156
+ await builder.simpleSpend(
157
+ [note],
158
+ [spendCondition],
159
+ new Digest("recipient_address"),
162
160
  1234567, // gift
163
- 2850816, // fee
164
- new WasmDigest("refund_address")
161
+ 2850816, // fee override
162
+ new Digest("refund_address"),
163
+ true
165
164
  );
166
165
 
167
166
  // Sign and submit
168
- const signedTx = builder.sign(masterKey.private_key);
167
+ const privateKey = PrivateKey.fromBytes(masterKey.private_key);
168
+ await builder.sign(privateKey);
169
+ const signedTx = builder.build();
169
170
  const txProtobuf = signedTx.toProtobuf();
170
- await client.send_transaction(txProtobuf);
171
+ await client.sendTransaction(txProtobuf);
171
172
 
172
173
  // Check if a transaction was accepted
173
- const accepted = await client.transaction_accepted(signedTx.id.value);
174
+ const accepted = await client.transactionAccepted(signedTx.id.value);
174
175
  console.log('Transaction accepted:', accepted);
175
176
  ```
176
177
 
@@ -187,22 +188,22 @@ Creates a new gRPC-Web client.
187
188
 
188
189
  #### Methods
189
190
 
190
- ##### `get_balance_by_address(address: string): Promise<Balance>`
191
+ ##### `getBalanceByAddress(address: string): Promise<Balance>`
191
192
  Get the balance for a wallet address.
192
193
  - `address`: Base58-encoded wallet address
193
194
  - Returns: Balance object with notes, height, and block_id
194
195
 
195
- ##### `get_balance_by_first_name(firstName: string): Promise<Balance>`
196
+ ##### `getBalanceByFirstName(firstName: string): Promise<Balance>`
196
197
  Get the balance for a note first name.
197
198
  - `firstName`: Base58-encoded first name hash
198
199
  - Returns: Balance object with notes, height, and block_id
199
200
 
200
- ##### `send_transaction(rawTx: RawTransaction): Promise<string>`
201
+ ##### `sendTransaction(rawTx: RawTransaction): Promise<string>`
201
202
  Send a signed transaction to the network.
202
203
  - `rawTx`: RawTransaction object (must include tx_id)
203
204
  - Returns: Acknowledgment message
204
205
 
205
- ##### `transaction_accepted(txId: string): Promise<boolean>`
206
+ ##### `transactionAccepted(txId: string): Promise<boolean>`
206
207
  Check if a transaction has been accepted.
207
208
  - `txId`: Base58-encoded transaction ID
208
209
  - Returns: `true` if accepted, `false` otherwise