@lerna-labs/hydra-sdk 1.0.0-beta.25 → 1.0.0-beta.27

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.d.ts CHANGED
@@ -11,5 +11,5 @@ export { getAdmin } from './mesh/get-admin.js';
11
11
  export { createMultisigAddress, createNativeScript } from './mesh/native-script.js';
12
12
  export { submitTx } from './tx3/submit-tx.js';
13
13
  export { chunkString } from './utils/chunk-string.js';
14
- export { bufferToAscii, bufferToHex, verifySignature } from './utils/verify-signature.js';
14
+ export { BECH32_DECODE_LIMIT, bufferToAscii, bufferToHex, decodeBech32Address, verifySignature, } from './utils/verify-signature.js';
15
15
  export { CommitArgs, UTxORef, Wrangler } from './wrangler.js';
package/dist/index.js CHANGED
@@ -7,5 +7,5 @@ export { getAdmin } from './mesh/get-admin.js';
7
7
  export { createMultisigAddress, createNativeScript } from './mesh/native-script.js';
8
8
  export { submitTx } from './tx3/submit-tx.js';
9
9
  export { chunkString } from './utils/chunk-string.js';
10
- export { bufferToAscii, bufferToHex, verifySignature } from './utils/verify-signature.js';
10
+ export { BECH32_DECODE_LIMIT, bufferToAscii, bufferToHex, decodeBech32Address, verifySignature, } from './utils/verify-signature.js';
11
11
  export { Wrangler } from './wrangler.js';
package/dist/ipfs/ipfs.js CHANGED
@@ -35,15 +35,28 @@ export function createIpfsClient(config) {
35
35
  * @returns The CID of the wrapping IPFS directory.
36
36
  */
37
37
  async function pinDirectory(dirPath) {
38
- const entries = await fs.readdir(dirPath);
39
38
  const form = new FormData();
40
- for (const entry of entries) {
41
- const filePath = path.join(dirPath, entry);
42
- const stat = await fs.stat(filePath);
43
- if (!stat.isFile())
44
- continue;
45
- const content = await fs.readFile(filePath, 'utf-8');
46
- form.append('file', new Blob([content]), entry);
39
+ const collectFiles = async (rel) => {
40
+ const out = [];
41
+ const dirents = await fs.readdir(path.join(dirPath, rel), { withFileTypes: true });
42
+ for (const dirent of dirents) {
43
+ const childRel = path.join(rel, dirent.name);
44
+ if (dirent.isDirectory()) {
45
+ out.push(...(await collectFiles(childRel)));
46
+ }
47
+ else if (dirent.isFile()) {
48
+ out.push(childRel);
49
+ }
50
+ }
51
+ return out;
52
+ };
53
+ for (const relPath of await collectFiles('')) {
54
+ const buf = await fs.readFile(path.join(dirPath, relPath));
55
+ const content = new Uint8Array(buf).slice().buffer;
56
+ // Kubo reconstructs the directory tree from entry names — always
57
+ // use POSIX separators so Windows callers get the same CID.
58
+ const entryName = relPath.split(path.sep).join('/');
59
+ form.append('file', new Blob([content]), entryName);
47
60
  }
48
61
  const res = await fetch(`${apiUrl}/api/v0/add?pin=true&wrap-with-directory=true&recursive=true`, {
49
62
  method: 'POST',
@@ -1,7 +1,22 @@
1
+ import { Buffer } from 'node:buffer';
1
2
  /** Convert a buffer-like value to a hex string. */
2
3
  export declare const bufferToHex: (buffer: Uint8Array | string) => string;
3
4
  /** Convert a buffer-like value to an ASCII string. */
4
5
  export declare const bufferToAscii: (buffer: Uint8Array | string) => string;
6
+ /**
7
+ * Character limit used for bech32 decoding. The library defaults to 90, which truncates
8
+ * Cardano base addresses (payment + staking) that are commonly 103+ characters. We raise
9
+ * the ceiling well above any realistic Cardano encoding (addr, stake, drep, pool, cc_*).
10
+ */
11
+ export declare const BECH32_DECODE_LIMIT = 1023;
12
+ /**
13
+ * Decode a Cardano bech32 string (addr, stake, pool, drep, cc_*) with a character
14
+ * limit high enough to accommodate base addresses that include a staking component.
15
+ */
16
+ export declare function decodeBech32Address(address: string): {
17
+ prefix: string;
18
+ addressBytes: Buffer;
19
+ };
5
20
  /**
6
21
  * Verify a CIP-30 COSE_Sign1 signature against an expected message and address.
7
22
  *
@@ -8,6 +8,20 @@ import { chunkString } from './chunk-string.js';
8
8
  export const bufferToHex = (buffer) => Buffer.from(buffer).toString('hex');
9
9
  /** Convert a buffer-like value to an ASCII string. */
10
10
  export const bufferToAscii = (buffer) => Buffer.from(buffer).toString('ascii');
11
+ /**
12
+ * Character limit used for bech32 decoding. The library defaults to 90, which truncates
13
+ * Cardano base addresses (payment + staking) that are commonly 103+ characters. We raise
14
+ * the ceiling well above any realistic Cardano encoding (addr, stake, drep, pool, cc_*).
15
+ */
16
+ export const BECH32_DECODE_LIMIT = 1023;
17
+ /**
18
+ * Decode a Cardano bech32 string (addr, stake, pool, drep, cc_*) with a character
19
+ * limit high enough to accommodate base addresses that include a staking component.
20
+ */
21
+ export function decodeBech32Address(address) {
22
+ const { words, prefix } = bech32.decode(address, BECH32_DECODE_LIMIT);
23
+ return { prefix, addressBytes: Buffer.from(bech32.fromWords(words)) };
24
+ }
11
25
  /**
12
26
  * Verify a CIP-30 COSE_Sign1 signature against an expected message and address.
13
27
  *
@@ -23,8 +37,7 @@ export function verifySignature(signature, message, signingAddress, signatureKey
23
37
  const signatureBytes = coseSign1.signature();
24
38
  const [, , , payload1] = cbor.decode(bufferToHex(coseSign1.signed_data().to_bytes()));
25
39
  const signaturePayloadAscii = bufferToAscii(payload1);
26
- const { words, prefix } = bech32.decode(signingAddress);
27
- const addressBytes = Buffer.from(bech32.fromWords(words));
40
+ const { prefix, addressBytes } = decodeBech32Address(signingAddress);
28
41
  const coseSigKey = cbor.decode(signatureKey);
29
42
  const cosePublicKey = coseSigKey.get(-2);
30
43
  const sigKey = CSL.PublicKey.from_bytes(cosePublicKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lerna-labs/hydra-sdk",
3
- "version": "1.0.0-beta.25",
3
+ "version": "1.0.0-beta.27",
4
4
  "description": "TypeScript SDK for managing Cardano Hydra Heads — lifecycle, UTxO queries, wallet management, transaction submission, and signature verification",
5
5
  "keywords": [
6
6
  "cardano",