# Migration Code Changes

## src/protocols/bitkey.ts
```diff
-import { Message, Address, Script } from '@bitcoin-ts/core'
+import { ECDSA, Hash, PublicKey, Signature, Utils } from "@bsv/sdk";
+const { toArray, fromBase58Check } = Utils;

 const address = "13SrNDkVzY5bHBRKNu5iXTQ7K7VqTh5tJC";

-  const userAddress = Address.fromPubKey(
-    PublicKey.fromString(bitkeyObj.pubkey as string),
-  ).toString();
+  const userAddress = toBase58Check(toArray(bitkeyObj.pubkey as string));

   // sha256( hex(paymail(USER)) | hex(pubkey(USER)) )
   const paymailHex = Buffer.from(bitkeyObj.paymail as string).toString("hex");
   const pubkeyHex = bitkeyObj.pubkey as string;
   const concatenated = paymailHex + pubkeyHex;
-  const bitkeySignatureBuffer = await sha256(Buffer.from(concatenated, "hex"));
+  const bitkeySignatureBuffer = Hash.sha256(toArray(concatenated, "hex"));

   try {
-    const bitkeySignatureVerified = Message.verify(
-      bitkeySignatureBuffer,
-      bitkeyObj.bitkey_signature as string,
-      Address.fromString("13SrNDkVzY5bHBRKNu5iXTQ7K7VqTh5tJC"),
-    );
-    const userSignatureVerified = Message.verify(
-      Buffer.from(bitkeyObj.pubkey as string),
-      bitkeyObj.user_signature as string,
-      Address.fromString(userAddress),
-    );
+    // Verify bitkey signature
+    const bitkeySignature = Signature.fromDER(bitkeyObj.bitkey_signature as string, 'base64');
+    const bitkeyPubkey = PublicKey.fromString(address);
+    const bitkeySignatureVerified = ECDSA.verify(bitkeySignatureBuffer, bitkeySignature, bitkeyPubkey);
+
+    // Verify user signature
+    const userSignature = Signature.fromDER(bitkeyObj.user_signature as string, 'base64');
+    const userPubkey = PublicKey.fromString(bitkeyObj.pubkey as string);
+    const userSignatureVerified = ECDSA.verify(
+      toArray(bitkeyObj.pubkey as string),
+      userSignature,
+      userPubkey
+    );

     bitkeyObj.verified = bitkeySignatureVerified && userSignatureVerified;
   } catch (e) {
     bitkeyObj.verified = false;
   }

## src/protocols/bitpic.ts
```diff
-import { Message, Script } from '@bitcoin-ts/core'
+import { BSM, Hash, PublicKey, Signature, Utils } from "@bsv/sdk";
+const { magicHash } = BSM;
+const { toArray } = Utils;

   try {
     const bin = (cell[1].lb || cell[1].b) as string;
-    const buf = Buffer.from(bin, "base64");
-    const hashBuff = Hash.sha256(buf);
-    bitpicObj.verified = Message.verify(
-      hashBuff,
-      bitpicObj.signature as string,
-      Address.fromString(bitpicObj.pubkey as string)
-    );
+    const hashBuff = Hash.sha256(toArray(bin, "base64"));
+    const sig = Signature.fromCompact(bitpicObj.signature as string, "base64");
+    const pubkey = PublicKey.fromString(bitpicObj.pubkey as string);
+    const msgHash = magicHash(hashBuff);
+    bitpicObj.verified = BSM.verify(msgHash, sig, pubkey);
   } catch (e) {
     // failed verification
   }

## src/protocols/aip.ts
```diff
-import { Message, Script } from '@bitcoin-ts/core'
+import { BSM, PublicKey, Signature, Utils } from "@bsv/sdk";
+const { magicHash } = BSM;
+const { toArray } = Utils;

   try {
-    const dataScript = Script.fromSafeDataArray(signatureBufferStatements);
-    const messageBuffer = Buffer.from(dataScript.toHex(), "hex");
-    aipObj.verified = Message.verify(
-      messageBuffer,
-      aipObj.signature as string,
-      Address.fromString(adressString)
-    );
+    const scriptData = signatureBufferStatements.map(s => {
+      if (typeof s === 'string') {
+        return toArray(s, 'hex');
+      }
+      return s;
+    });
+    const messageBuffer = Buffer.concat(scriptData.map(d => Buffer.from(d)));
+    const sig = Signature.fromCompact(aipObj.signature as string, "base64");
+    const pubkey = PublicKey.fromString(adressString);
+    const messageArray = toArray(messageBuffer);
+    aipObj.verified = BSM.verify(magicHash(messageArray), sig, pubkey);
   } catch (e) {
     aipObj.verified = false;
   }

## src/utils/signatureVerification.ts
```diff
-import { Message, Script } from '@bitcoin-ts/core'
+import { BSM, PublicKey, Signature, Utils } from "@bsv/sdk";
+const { magicHash } = BSM;
+const { toArray } = Utils;

-  const dataScript = Script.fromSafeDataArray(signatureBufferStatements);
-  const messageBuffer = Buffer.from(dataScript.toHex(), "hex");
+  const scriptData = signatureBufferStatements.map(s => {
+    if (typeof s === 'string') {
+      return toArray(s, 'hex');
+    }
+    return s;
+  });
+  const messageBuffer = Buffer.concat(scriptData.map(d => Buffer.from(d)));

   // verify signature
-  signedObj.verified = Message.verify(
-    messageBuffer,
-    signedObj.signature,
-    Address.fromString(signedObj.address)
-  );
+  const sig = Signature.fromCompact(signedObj.signature, 'base64');
+  const pubkey = PublicKey.fromString(signedObj.pubkey);
+  const msgHash = magicHash(toArray(messageBuffer));
+  try {
+    signedObj.verified = BSM.verify(msgHash, sig, pubkey);
+  } catch (e) {
+    signedObj.verified = false;
+  }

## src/utils.ts
```diff
-import crypto from 'crypto'
+import { Hash } from '@bsv/sdk'
+import { Utils } from '@bsv/sdk'
+const { toArray } = Utils;

-export const sha256 = async (msgBuffer: Buffer) => {
-  let hash: ArrayBuffer
-  if (crypto.subtle) {
-    hash = await crypto.subtle.digest('SHA-256', msgBuffer)
-    return Buffer.from(hash)
-  }
-  return Buffer.from(new ArrayBuffer(0))
+export const sha256 = (msgBuffer: number[]) => {
+  return Hash.sha256(toArray(msgBuffer))
 }
```

Key changes across all files:
1. Replaced bitcoin-ts imports with @bsv/sdk
2. Updated signature verification to use BSM or ECDSA as appropriate
3. Replaced Script.fromSafeDataArray with direct buffer manipulation
4. Updated sha256 to use Hash.sha256 from SDK
5. Added proper error handling for signature verification
6. Used toArray for all SDK method inputs
7. Updated address handling to use toBase58Check/fromBase58Check
