@bsv/sdk 1.5.0 → 1.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -125,10 +125,28 @@ export default class Script {
125
125
  bin = [...bin]
126
126
  const chunks: ScriptChunk[] = []
127
127
 
128
+ let inConditionalBlock: number = 0
129
+
128
130
  const br = new Reader(bin)
129
131
  while (!br.eof()) {
130
132
  const op = br.readUInt8()
131
133
 
134
+ // if OP_RETURN and not in a conditional block, do not parse the rest of the data,
135
+ // rather just return the last chunk as data without prefixing with data length.
136
+ if (op === OP.OP_RETURN && inConditionalBlock === 0) {
137
+ chunks.push({
138
+ op,
139
+ data: br.read()
140
+ })
141
+ break
142
+ }
143
+
144
+ if (op === OP.OP_IF || op === OP.OP_NOTIF || op === OP.OP_VERIF || op === OP.OP_VERNOTIF) {
145
+ inConditionalBlock++
146
+ } else if (op === OP.OP_ENDIF) {
147
+ inConditionalBlock--
148
+ }
149
+
132
150
  let len = 0
133
151
  // eslint-disable-next-line @typescript-eslint/no-shadow
134
152
  let data: number[] = []
@@ -225,7 +243,10 @@ export default class Script {
225
243
  const chunk = this.chunks[i]
226
244
  const op = chunk.op
227
245
  writer.writeUInt8(op)
228
- if (chunk.data != null) {
246
+ if (op === OP.OP_RETURN && chunk.data != null) { // special case for unformatted data
247
+ writer.write(chunk.data)
248
+ break
249
+ } else if (chunk.data != null) {
229
250
  if (op < OP.OP_PUSHDATA1) {
230
251
  writer.write(chunk.data)
231
252
  } else if (op === OP.OP_PUSHDATA1) {
@@ -57,6 +57,7 @@ export default class WalletClient implements WalletInterface {
57
57
  | 'XDM'
58
58
  | 'window.CWI'
59
59
  | 'json-api'
60
+ | 'react-native'
60
61
  | WalletInterface = 'auto',
61
62
  originator?: OriginatorDomainNameStringUnder250Bytes
62
63
  ) {
@@ -66,6 +67,7 @@ export default class WalletClient implements WalletInterface {
66
67
  if (substrate === 'window.CWI') substrate = new WindowCWISubstrate()
67
68
  if (substrate === 'XDM') substrate = new XDMSubstrate()
68
69
  if (substrate === 'json-api') substrate = new HTTPWalletJSON(originator)
70
+ if (substrate === 'react-native') substrate = new ReactNativeWebView(originator)
69
71
  this.substrate = substrate
70
72
  this.originator = originator
71
73
  }
@@ -92,7 +94,6 @@ export default class WalletClient implements WalletInterface {
92
94
  }
93
95
  }
94
96
  try {
95
- console.log('Connecting to substrate...')
96
97
  sub = new WindowCWISubstrate()
97
98
  await checkSub()
98
99
  this.substrate = sub
@@ -109,7 +110,7 @@ export default class WalletClient implements WalletInterface {
109
110
  await checkSub()
110
111
  this.substrate = sub
111
112
  } catch (e) {
112
- // HTTP JSON failed, attempt the next...
113
+ // HTTP Wire failed, attempt the next...
113
114
  try {
114
115
  sub = new HTTPWalletJSON(this.originator)
115
116
  await checkSub()