@pioneer-platform/pioneer-sdk 8.15.34 → 8.15.38

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/dist/index.cjs CHANGED
@@ -4837,14 +4837,17 @@ class SDK {
4837
4837
  this.getUnifiedPortfolio = async function() {
4838
4838
  const tag6 = `${TAG12} | getUnifiedPortfolio | `;
4839
4839
  try {
4840
+ console.log(tag6, " checkpoint 4.0 - getUnifiedPortfolio start");
4840
4841
  const startTime = performance.now();
4841
4842
  try {
4842
4843
  const baseUrl = this.keepkeyEndpoint?.baseUrl || "kkapi://";
4843
4844
  const portfolioUrl = `${baseUrl}/api/portfolio`;
4845
+ console.log(tag6, " checkpoint 4.1 - Fetching portfolio from:", portfolioUrl);
4844
4846
  const portfolioResponse = await fetch(portfolioUrl, {
4845
4847
  method: "GET",
4846
4848
  signal: AbortSignal.timeout(2000)
4847
4849
  });
4850
+ console.log(tag6, " checkpoint 4.2 - Portfolio fetch returned, status:", portfolioResponse.status);
4848
4851
  if (!portfolioResponse.ok) {
4849
4852
  console.warn(tag6, "Portfolio endpoint returned", portfolioResponse.status);
4850
4853
  return null;
@@ -4957,7 +4960,9 @@ class SDK {
4957
4960
  };
4958
4961
  console.log("\uD83D\uDD11 [INIT] Initializing KeepKey SDK...");
4959
4962
  const keepKeySdk = await import_keepkey_sdk.KeepKeySdk.create(configKeepKey);
4963
+ console.log(tag6, " checkpoint 1.1 - KeepKeySdk created");
4960
4964
  const features = await keepKeySdk.system.info.getFeatures();
4965
+ console.log(tag6, " checkpoint 1.2 - features retrieved:", features);
4961
4966
  this.keepkeyApiKey = configKeepKey.apiKey;
4962
4967
  this.keepKeySdk = keepKeySdk;
4963
4968
  this.context = "keepkey:" + features.label + ".json";
@@ -4971,14 +4976,18 @@ class SDK {
4971
4976
  console.log("\uD83D\uDC41️ [VIEW-ONLY] Skipping vault endpoint detection");
4972
4977
  this.keepkeyEndpoint = null;
4973
4978
  }
4979
+ console.log(tag6, " checkpoint 2 - Starting WebSocket initialization");
4974
4980
  let configWss = {
4975
4981
  username: this.username,
4976
4982
  queryKey: this.queryKey,
4977
4983
  wss: this.wss
4978
4984
  };
4979
4985
  let clientEvents = new import_pioneer_events.Events(configWss);
4986
+ console.log(tag6, " checkpoint 2.1 - Events created, calling init()");
4980
4987
  await clientEvents.init();
4988
+ console.log(tag6, " checkpoint 2.2 - Events init complete, setting username");
4981
4989
  await clientEvents.setUsername(this.username);
4990
+ console.log(tag6, " checkpoint 2.3 - Username set, WebSocket ready");
4982
4991
  clientEvents.events.on("message", (request) => {
4983
4992
  this.events.emit("message", request);
4984
4993
  });
@@ -5044,11 +5053,14 @@ class SDK {
5044
5053
  }
5045
5054
  });
5046
5055
  this.events.emit("SET_STATUS", "init");
5056
+ console.log(tag6, " checkpoint 3 - Starting fast portfolio check");
5047
5057
  if (this.keepKeySdk && !skipSync) {
5048
5058
  console.log("⚡ [FAST PORTFOLIO] Attempting fast load...");
5059
+ console.log(tag6, " checkpoint 3.1 - Calling getUnifiedPortfolio()");
5049
5060
  const fastStart = performance.now();
5050
5061
  try {
5051
5062
  const unifiedResult = await this.getUnifiedPortfolio();
5063
+ console.log(tag6, " checkpoint 3.2 - getUnifiedPortfolio() returned");
5052
5064
  console.log("unifiedResult: ", unifiedResult);
5053
5065
  if (unifiedResult && unifiedResult.cached && unifiedResult.totalValueUsd > 0) {
5054
5066
  console.log(`✅ [FAST PORTFOLIO] Loaded in ${(performance.now() - fastStart).toFixed(0)}ms`);
@@ -5979,7 +5991,16 @@ class SDK {
5979
5991
  const networkId2 = import_pioneer_caip8.caipToNetworkId(asset.caip || asset.networkId);
5980
5992
  const currentContextValid = this.pubkeyContext?.networks?.includes(networkId2);
5981
5993
  if (!this.pubkeyContext || !currentContextValid) {
5982
- this.pubkeyContext = assetPubkeys[0];
5994
+ let preferredPubkey = assetPubkeys[0];
5995
+ const isBitcoin = networkId2?.includes("bip122:000000000019d6689c085ae165831e93") || asset.symbol === "BTC" || asset.name?.toLowerCase().includes("bitcoin");
5996
+ if (isBitcoin) {
5997
+ const nativeSegwitPubkey = assetPubkeys.find((pk) => pk.script_type === "p2wpkh" || pk.scriptType === "p2wpkh" || pk.note?.toLowerCase().includes("native") && pk.note?.toLowerCase().includes("segwit") || pk.pathMaster?.includes("84'"));
5998
+ if (nativeSegwitPubkey) {
5999
+ preferredPubkey = nativeSegwitPubkey;
6000
+ console.log(tag6, "Preferring Native Segwit (Bech32) for Bitcoin");
6001
+ }
6002
+ }
6003
+ this.pubkeyContext = preferredPubkey;
5983
6004
  console.log(tag6, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
5984
6005
  } else {
5985
6006
  console.log(tag6, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
package/dist/index.es.js CHANGED
@@ -5021,14 +5021,17 @@ class SDK {
5021
5021
  this.getUnifiedPortfolio = async function() {
5022
5022
  const tag6 = `${TAG12} | getUnifiedPortfolio | `;
5023
5023
  try {
5024
+ console.log(tag6, " checkpoint 4.0 - getUnifiedPortfolio start");
5024
5025
  const startTime = performance.now();
5025
5026
  try {
5026
5027
  const baseUrl = this.keepkeyEndpoint?.baseUrl || "kkapi://";
5027
5028
  const portfolioUrl = `${baseUrl}/api/portfolio`;
5029
+ console.log(tag6, " checkpoint 4.1 - Fetching portfolio from:", portfolioUrl);
5028
5030
  const portfolioResponse = await fetch(portfolioUrl, {
5029
5031
  method: "GET",
5030
5032
  signal: AbortSignal.timeout(2000)
5031
5033
  });
5034
+ console.log(tag6, " checkpoint 4.2 - Portfolio fetch returned, status:", portfolioResponse.status);
5032
5035
  if (!portfolioResponse.ok) {
5033
5036
  console.warn(tag6, "Portfolio endpoint returned", portfolioResponse.status);
5034
5037
  return null;
@@ -5141,7 +5144,9 @@ class SDK {
5141
5144
  };
5142
5145
  console.log("\uD83D\uDD11 [INIT] Initializing KeepKey SDK...");
5143
5146
  const keepKeySdk = await KeepKeySdk.create(configKeepKey);
5147
+ console.log(tag6, " checkpoint 1.1 - KeepKeySdk created");
5144
5148
  const features = await keepKeySdk.system.info.getFeatures();
5149
+ console.log(tag6, " checkpoint 1.2 - features retrieved:", features);
5145
5150
  this.keepkeyApiKey = configKeepKey.apiKey;
5146
5151
  this.keepKeySdk = keepKeySdk;
5147
5152
  this.context = "keepkey:" + features.label + ".json";
@@ -5155,14 +5160,18 @@ class SDK {
5155
5160
  console.log("\uD83D\uDC41️ [VIEW-ONLY] Skipping vault endpoint detection");
5156
5161
  this.keepkeyEndpoint = null;
5157
5162
  }
5163
+ console.log(tag6, " checkpoint 2 - Starting WebSocket initialization");
5158
5164
  let configWss = {
5159
5165
  username: this.username,
5160
5166
  queryKey: this.queryKey,
5161
5167
  wss: this.wss
5162
5168
  };
5163
5169
  let clientEvents = new Events(configWss);
5170
+ console.log(tag6, " checkpoint 2.1 - Events created, calling init()");
5164
5171
  await clientEvents.init();
5172
+ console.log(tag6, " checkpoint 2.2 - Events init complete, setting username");
5165
5173
  await clientEvents.setUsername(this.username);
5174
+ console.log(tag6, " checkpoint 2.3 - Username set, WebSocket ready");
5166
5175
  clientEvents.events.on("message", (request) => {
5167
5176
  this.events.emit("message", request);
5168
5177
  });
@@ -5228,11 +5237,14 @@ class SDK {
5228
5237
  }
5229
5238
  });
5230
5239
  this.events.emit("SET_STATUS", "init");
5240
+ console.log(tag6, " checkpoint 3 - Starting fast portfolio check");
5231
5241
  if (this.keepKeySdk && !skipSync) {
5232
5242
  console.log("⚡ [FAST PORTFOLIO] Attempting fast load...");
5243
+ console.log(tag6, " checkpoint 3.1 - Calling getUnifiedPortfolio()");
5233
5244
  const fastStart = performance.now();
5234
5245
  try {
5235
5246
  const unifiedResult = await this.getUnifiedPortfolio();
5247
+ console.log(tag6, " checkpoint 3.2 - getUnifiedPortfolio() returned");
5236
5248
  console.log("unifiedResult: ", unifiedResult);
5237
5249
  if (unifiedResult && unifiedResult.cached && unifiedResult.totalValueUsd > 0) {
5238
5250
  console.log(`✅ [FAST PORTFOLIO] Loaded in ${(performance.now() - fastStart).toFixed(0)}ms`);
@@ -6163,7 +6175,16 @@ class SDK {
6163
6175
  const networkId2 = caipToNetworkId7(asset.caip || asset.networkId);
6164
6176
  const currentContextValid = this.pubkeyContext?.networks?.includes(networkId2);
6165
6177
  if (!this.pubkeyContext || !currentContextValid) {
6166
- this.pubkeyContext = assetPubkeys[0];
6178
+ let preferredPubkey = assetPubkeys[0];
6179
+ const isBitcoin = networkId2?.includes("bip122:000000000019d6689c085ae165831e93") || asset.symbol === "BTC" || asset.name?.toLowerCase().includes("bitcoin");
6180
+ if (isBitcoin) {
6181
+ const nativeSegwitPubkey = assetPubkeys.find((pk) => pk.script_type === "p2wpkh" || pk.scriptType === "p2wpkh" || pk.note?.toLowerCase().includes("native") && pk.note?.toLowerCase().includes("segwit") || pk.pathMaster?.includes("84'"));
6182
+ if (nativeSegwitPubkey) {
6183
+ preferredPubkey = nativeSegwitPubkey;
6184
+ console.log(tag6, "Preferring Native Segwit (Bech32) for Bitcoin");
6185
+ }
6186
+ }
6187
+ this.pubkeyContext = preferredPubkey;
6167
6188
  console.log(tag6, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
6168
6189
  } else {
6169
6190
  console.log(tag6, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
package/dist/index.js CHANGED
@@ -5021,14 +5021,17 @@ class SDK {
5021
5021
  this.getUnifiedPortfolio = async function() {
5022
5022
  const tag6 = `${TAG12} | getUnifiedPortfolio | `;
5023
5023
  try {
5024
+ console.log(tag6, " checkpoint 4.0 - getUnifiedPortfolio start");
5024
5025
  const startTime = performance.now();
5025
5026
  try {
5026
5027
  const baseUrl = this.keepkeyEndpoint?.baseUrl || "kkapi://";
5027
5028
  const portfolioUrl = `${baseUrl}/api/portfolio`;
5029
+ console.log(tag6, " checkpoint 4.1 - Fetching portfolio from:", portfolioUrl);
5028
5030
  const portfolioResponse = await fetch(portfolioUrl, {
5029
5031
  method: "GET",
5030
5032
  signal: AbortSignal.timeout(2000)
5031
5033
  });
5034
+ console.log(tag6, " checkpoint 4.2 - Portfolio fetch returned, status:", portfolioResponse.status);
5032
5035
  if (!portfolioResponse.ok) {
5033
5036
  console.warn(tag6, "Portfolio endpoint returned", portfolioResponse.status);
5034
5037
  return null;
@@ -5141,7 +5144,9 @@ class SDK {
5141
5144
  };
5142
5145
  console.log("\uD83D\uDD11 [INIT] Initializing KeepKey SDK...");
5143
5146
  const keepKeySdk = await KeepKeySdk.create(configKeepKey);
5147
+ console.log(tag6, " checkpoint 1.1 - KeepKeySdk created");
5144
5148
  const features = await keepKeySdk.system.info.getFeatures();
5149
+ console.log(tag6, " checkpoint 1.2 - features retrieved:", features);
5145
5150
  this.keepkeyApiKey = configKeepKey.apiKey;
5146
5151
  this.keepKeySdk = keepKeySdk;
5147
5152
  this.context = "keepkey:" + features.label + ".json";
@@ -5155,14 +5160,18 @@ class SDK {
5155
5160
  console.log("\uD83D\uDC41️ [VIEW-ONLY] Skipping vault endpoint detection");
5156
5161
  this.keepkeyEndpoint = null;
5157
5162
  }
5163
+ console.log(tag6, " checkpoint 2 - Starting WebSocket initialization");
5158
5164
  let configWss = {
5159
5165
  username: this.username,
5160
5166
  queryKey: this.queryKey,
5161
5167
  wss: this.wss
5162
5168
  };
5163
5169
  let clientEvents = new Events(configWss);
5170
+ console.log(tag6, " checkpoint 2.1 - Events created, calling init()");
5164
5171
  await clientEvents.init();
5172
+ console.log(tag6, " checkpoint 2.2 - Events init complete, setting username");
5165
5173
  await clientEvents.setUsername(this.username);
5174
+ console.log(tag6, " checkpoint 2.3 - Username set, WebSocket ready");
5166
5175
  clientEvents.events.on("message", (request) => {
5167
5176
  this.events.emit("message", request);
5168
5177
  });
@@ -5228,11 +5237,14 @@ class SDK {
5228
5237
  }
5229
5238
  });
5230
5239
  this.events.emit("SET_STATUS", "init");
5240
+ console.log(tag6, " checkpoint 3 - Starting fast portfolio check");
5231
5241
  if (this.keepKeySdk && !skipSync) {
5232
5242
  console.log("⚡ [FAST PORTFOLIO] Attempting fast load...");
5243
+ console.log(tag6, " checkpoint 3.1 - Calling getUnifiedPortfolio()");
5233
5244
  const fastStart = performance.now();
5234
5245
  try {
5235
5246
  const unifiedResult = await this.getUnifiedPortfolio();
5247
+ console.log(tag6, " checkpoint 3.2 - getUnifiedPortfolio() returned");
5236
5248
  console.log("unifiedResult: ", unifiedResult);
5237
5249
  if (unifiedResult && unifiedResult.cached && unifiedResult.totalValueUsd > 0) {
5238
5250
  console.log(`✅ [FAST PORTFOLIO] Loaded in ${(performance.now() - fastStart).toFixed(0)}ms`);
@@ -6163,7 +6175,16 @@ class SDK {
6163
6175
  const networkId2 = caipToNetworkId7(asset.caip || asset.networkId);
6164
6176
  const currentContextValid = this.pubkeyContext?.networks?.includes(networkId2);
6165
6177
  if (!this.pubkeyContext || !currentContextValid) {
6166
- this.pubkeyContext = assetPubkeys[0];
6178
+ let preferredPubkey = assetPubkeys[0];
6179
+ const isBitcoin = networkId2?.includes("bip122:000000000019d6689c085ae165831e93") || asset.symbol === "BTC" || asset.name?.toLowerCase().includes("bitcoin");
6180
+ if (isBitcoin) {
6181
+ const nativeSegwitPubkey = assetPubkeys.find((pk) => pk.script_type === "p2wpkh" || pk.scriptType === "p2wpkh" || pk.note?.toLowerCase().includes("native") && pk.note?.toLowerCase().includes("segwit") || pk.pathMaster?.includes("84'"));
6182
+ if (nativeSegwitPubkey) {
6183
+ preferredPubkey = nativeSegwitPubkey;
6184
+ console.log(tag6, "Preferring Native Segwit (Bech32) for Bitcoin");
6185
+ }
6186
+ }
6187
+ this.pubkeyContext = preferredPubkey;
6167
6188
  console.log(tag6, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
6168
6189
  } else {
6169
6190
  console.log(tag6, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "author": "highlander",
3
3
  "name": "@pioneer-platform/pioneer-sdk",
4
- "version": "8.15.34",
4
+ "version": "8.15.38",
5
5
  "dependencies": {
6
6
  "@keepkey/keepkey-sdk": "^0.2.62",
7
- "@pioneer-platform/pioneer-caip": "^9.10.11",
8
- "@pioneer-platform/pioneer-client": "^9.10.17",
9
- "@pioneer-platform/pioneer-coins": "^9.11.11",
10
- "@pioneer-platform/pioneer-discovery": "^8.15.34",
11
- "@pioneer-platform/pioneer-events": "^8.12.6",
7
+ "@pioneer-platform/pioneer-caip": "^9.10.15",
8
+ "@pioneer-platform/pioneer-client": "^9.10.21",
9
+ "@pioneer-platform/pioneer-coins": "^9.11.15",
10
+ "@pioneer-platform/pioneer-discovery": "^8.15.38",
11
+ "@pioneer-platform/pioneer-events": "^8.12.10",
12
12
  "coinselect": "^3.1.13",
13
13
  "eventemitter3": "^5.0.1",
14
14
  "neotraverse": "^0.6.8",
package/src/index.ts CHANGED
@@ -333,6 +333,7 @@ export class SDK {
333
333
  this.getUnifiedPortfolio = async function () {
334
334
  const tag = `${TAG} | getUnifiedPortfolio | `;
335
335
  try {
336
+ console.log(tag,' checkpoint 4.0 - getUnifiedPortfolio start')
336
337
  const startTime = performance.now();
337
338
 
338
339
  // Check if kkapi is available and use the detected endpoint
@@ -340,11 +341,13 @@ export class SDK {
340
341
  // Use the detected endpoint instead of hardcoded kkapi://
341
342
  const baseUrl = this.keepkeyEndpoint?.baseUrl || 'kkapi://';
342
343
  const portfolioUrl = `${baseUrl}/api/portfolio`;
344
+ console.log(tag,' checkpoint 4.1 - Fetching portfolio from:', portfolioUrl)
343
345
 
344
346
  const portfolioResponse = await fetch(portfolioUrl, {
345
347
  method: 'GET',
346
348
  signal: AbortSignal.timeout(2000), // 2 second timeout
347
349
  });
350
+ console.log(tag,' checkpoint 4.2 - Portfolio fetch returned, status:', portfolioResponse.status)
348
351
 
349
352
  if (!portfolioResponse.ok) {
350
353
  console.warn(tag, 'Portfolio endpoint returned', portfolioResponse.status);
@@ -495,8 +498,9 @@ export class SDK {
495
498
 
496
499
  console.log('🔑 [INIT] Initializing KeepKey SDK...');
497
500
  const keepKeySdk = await KeepKeySdk.create(configKeepKey);
501
+ console.log(tag,' checkpoint 1.1 - KeepKeySdk created')
498
502
  const features = await keepKeySdk.system.info.getFeatures();
499
-
503
+ console.log(tag,' checkpoint 1.2 - features retrieved:', features)
500
504
  this.keepkeyApiKey = configKeepKey.apiKey;
501
505
  this.keepKeySdk = keepKeySdk;
502
506
  this.context = 'keepkey:' + features.label + '.json';
@@ -512,6 +516,7 @@ export class SDK {
512
516
  }
513
517
 
514
518
  // Initialize WebSocket events
519
+ console.log(tag,' checkpoint 2 - Starting WebSocket initialization')
515
520
  let configWss = {
516
521
  username: this.username,
517
522
  queryKey: this.queryKey,
@@ -519,8 +524,11 @@ export class SDK {
519
524
  };
520
525
 
521
526
  let clientEvents = new Events(configWss);
527
+ console.log(tag,' checkpoint 2.1 - Events created, calling init()')
522
528
  await clientEvents.init();
529
+ console.log(tag,' checkpoint 2.2 - Events init complete, setting username')
523
530
  await clientEvents.setUsername(this.username);
531
+ console.log(tag,' checkpoint 2.3 - Username set, WebSocket ready')
524
532
 
525
533
  clientEvents.events.on('message', (request) => {
526
534
  this.events.emit('message', request);
@@ -620,12 +628,15 @@ export class SDK {
620
628
  this.events.emit('SET_STATUS', 'init');
621
629
 
622
630
  // Fast Portfolio Pattern: Try unified portfolio first, then sync if needed
631
+ console.log(tag,' checkpoint 3 - Starting fast portfolio check')
623
632
  if (this.keepKeySdk && !skipSync) {
624
633
  console.log('⚡ [FAST PORTFOLIO] Attempting fast load...');
634
+ console.log(tag,' checkpoint 3.1 - Calling getUnifiedPortfolio()')
625
635
  const fastStart = performance.now();
626
636
 
627
637
  try {
628
638
  const unifiedResult = await this.getUnifiedPortfolio();
639
+ console.log(tag,' checkpoint 3.2 - getUnifiedPortfolio() returned')
629
640
  console.log('unifiedResult: ', unifiedResult);
630
641
 
631
642
  if (unifiedResult && unifiedResult.cached && unifiedResult.totalValueUsd > 0) {
@@ -1976,8 +1987,30 @@ export class SDK {
1976
1987
  const currentContextValid = this.pubkeyContext?.networks?.includes(networkId);
1977
1988
 
1978
1989
  if (!this.pubkeyContext || !currentContextValid) {
1979
- // No context or wrong network - auto-set to first matching pubkey
1980
- this.pubkeyContext = assetPubkeys[0];
1990
+ // No context or wrong network - auto-set to preferred pubkey
1991
+ // For Bitcoin, prefer Native Segwit (Bech32) over legacy
1992
+ let preferredPubkey = assetPubkeys[0];
1993
+
1994
+ const isBitcoin = networkId?.includes('bip122:000000000019d6689c085ae165831e93') ||
1995
+ asset.symbol === 'BTC' ||
1996
+ asset.name?.toLowerCase().includes('bitcoin');
1997
+
1998
+ if (isBitcoin) {
1999
+ // Find Native Segwit pubkey (script_type: 'p2wpkh', path includes 84')
2000
+ const nativeSegwitPubkey = assetPubkeys.find((pk: any) =>
2001
+ pk.script_type === 'p2wpkh' ||
2002
+ pk.scriptType === 'p2wpkh' ||
2003
+ (pk.note?.toLowerCase().includes('native') && pk.note?.toLowerCase().includes('segwit')) ||
2004
+ pk.pathMaster?.includes("84'")
2005
+ );
2006
+
2007
+ if (nativeSegwitPubkey) {
2008
+ preferredPubkey = nativeSegwitPubkey;
2009
+ console.log(tag, 'Preferring Native Segwit (Bech32) for Bitcoin');
2010
+ }
2011
+ }
2012
+
2013
+ this.pubkeyContext = preferredPubkey;
1981
2014
  console.log(
1982
2015
  tag,
1983
2016
  'Auto-set pubkey context for network:',