mainnet-js 1.1.4 → 1.1.5

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.
@@ -837,10 +837,11 @@ describe(`Test cashtokens`, () => {
837
837
  aliceWallet.cashaddr!
838
838
  );
839
839
 
840
+ let tokenId;
840
841
  {
841
842
  const aliceUtxos = await aliceWallet.getAddressUtxos();
842
843
 
843
- const { unsignedTransaction, sourceOutputs } =
844
+ const { unsignedTransaction, sourceOutputs, tokenIds } =
844
845
  await aliceWatchWallet.tokenGenesis(
845
846
  {
846
847
  capability: "minting",
@@ -867,13 +868,20 @@ describe(`Test cashtokens`, () => {
867
868
  ).toBe(true);
868
869
  expect(sourceOutputs!.length).toBe(decoded.inputs.length);
869
870
  expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("00");
870
- }
871
871
 
872
- const genesisResponse = await aliceWallet.tokenGenesis({
873
- capability: "minting",
874
- commitment: "00",
875
- });
876
- const tokenId = genesisResponse.tokenIds![0];
872
+ const signed = await aliceWallet.signUnsignedTransaction(
873
+ unsignedTransaction!,
874
+ sourceOutputs!
875
+ );
876
+ await aliceWallet.submitTransaction(signed);
877
+
878
+ tokenId = tokenIds![0];
879
+
880
+ expect(await aliceWallet.getNftTokenBalance(tokenId)).toBe(1);
881
+ const tokenUtxos = await aliceWallet.getTokenUtxos(tokenId);
882
+ expect(tokenUtxos.length).toBe(1);
883
+ expect(tokenUtxos[0].token?.capability).toBe(NFTCapability.minting);
884
+ }
877
885
 
878
886
  {
879
887
  const aliceUtxos = await aliceWallet.getAddressUtxos();
@@ -908,12 +916,26 @@ describe(`Test cashtokens`, () => {
908
916
  expect(binToHex(sourceOutputs![0].token?.nft?.commitment!)).toBe("00");
909
917
  expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("00");
910
918
  expect(binToHex(decoded.outputs[1].token?.nft?.commitment!)).toBe("0a");
911
- }
912
919
 
913
- await aliceWallet.tokenMint(tokenId, {
914
- capability: "none",
915
- commitment: "0a",
916
- });
920
+ const signed = await aliceWallet.signUnsignedTransaction(
921
+ unsignedTransaction!,
922
+ sourceOutputs!
923
+ );
924
+ await aliceWallet.submitTransaction(signed);
925
+
926
+ expect(await aliceWallet.getNftTokenBalance(tokenId)).toBe(2);
927
+ const tokenUtxos = await aliceWallet.getTokenUtxos(tokenId);
928
+ expect(tokenUtxos.length).toBe(2);
929
+ expect(
930
+ tokenUtxos.filter(
931
+ (val) => val.token?.capability === NFTCapability.minting
932
+ ).length
933
+ ).toBe(1);
934
+ expect(
935
+ tokenUtxos.filter((val) => val.token?.capability === NFTCapability.none)
936
+ .length
937
+ ).toBe(1);
938
+ }
917
939
 
918
940
  {
919
941
  const aliceUtxos = await aliceWallet.getAddressUtxos();
@@ -949,6 +971,24 @@ describe(`Test cashtokens`, () => {
949
971
  expect(sourceOutputs!.length).toBe(decoded.inputs.length);
950
972
  expect(binToHex(sourceOutputs![0].token?.nft?.commitment!)).toBe("0a");
951
973
  expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("0a");
974
+
975
+ const signed = await aliceWallet.signUnsignedTransaction(
976
+ unsignedTransaction!,
977
+ sourceOutputs!
978
+ );
979
+ await aliceWallet.submitTransaction(signed);
980
+ expect(await aliceWallet.getNftTokenBalance(tokenId)).toBe(2);
981
+ const tokenUtxos = await aliceWallet.getTokenUtxos(tokenId);
982
+ expect(tokenUtxos.length).toBe(2);
983
+ expect(
984
+ tokenUtxos.filter(
985
+ (val) => val.token?.capability === NFTCapability.minting
986
+ ).length
987
+ ).toBe(1);
988
+ expect(
989
+ tokenUtxos.filter((val) => val.token?.capability === NFTCapability.none)
990
+ .length
991
+ ).toBe(1);
952
992
  }
953
993
  });
954
994
 
package/src/wallet/Wif.ts CHANGED
@@ -39,6 +39,7 @@ import {
39
39
  SendRequestArray,
40
40
  SendRequestType,
41
41
  SendResponse,
42
+ SourceOutput,
42
43
  TokenBurnRequest,
43
44
  TokenGenesisRequest,
44
45
  TokenMintRequest,
@@ -50,6 +51,7 @@ import {
50
51
  buildEncodedTransaction,
51
52
  getSuitableUtxos,
52
53
  getFeeAmount,
54
+ signUnsignedTransaction,
53
55
  } from "../transaction/Wif.js";
54
56
 
55
57
  import { asSendRequestObject } from "../util/asSendRequestObject.js";
@@ -1132,13 +1134,6 @@ export class Wallet extends BaseWallet {
1132
1134
  utxos = utxos.filter((val) => !val.token);
1133
1135
  }
1134
1136
 
1135
- // let tokenOp: "send" | "genesis" | "mint" | "burn" | undefined = undefined;
1136
- // if (options?.ensureUtxos?.every(val => !val.token) && sendRequests.some(val => (val as TokenSendRequest).tokenId)) {
1137
- // tokenOp = "genesis";
1138
- // } else if (options?.ensureUtxos?.length === 1 && options?.ensureUtxos?.[0].token?.capability === NFTCapability.minting && ) {
1139
-
1140
- // }
1141
-
1142
1137
  const addTokenChangeOutputs = (
1143
1138
  inputs: UtxoI[],
1144
1139
  outputs: SendRequestType[]
@@ -1245,6 +1240,7 @@ export class Wallet extends BaseWallet {
1245
1240
  slpOutputs: [],
1246
1241
  feePaidBy,
1247
1242
  changeAddress,
1243
+ buildUnsigned: options?.buildUnsigned === true,
1248
1244
  }
1249
1245
  );
1250
1246
 
@@ -1260,6 +1256,21 @@ export class Wallet extends BaseWallet {
1260
1256
  return { encodedTransaction, tokenIds, sourceOutputs };
1261
1257
  }
1262
1258
 
1259
+ public async signUnsignedTransaction(
1260
+ transaction: Uint8Array | string,
1261
+ sourceOutputs: SourceOutput[]
1262
+ ): Promise<Uint8Array> {
1263
+ if (!this.privateKey) {
1264
+ throw Error("Can not sign a transaction with watch-only wallet.");
1265
+ }
1266
+
1267
+ return signUnsignedTransaction(
1268
+ transaction,
1269
+ sourceOutputs,
1270
+ this.privateKey!
1271
+ );
1272
+ }
1273
+
1263
1274
  // Submit a raw transaction
1264
1275
  public async submitTransaction(
1265
1276
  transaction: Uint8Array,