@harmoniclabs/plutus-data
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -19,3 +19,5 @@ "use strict"; | ||
if (cborObj instanceof cbor_1.CborBytes) { | ||
return new DataB_1.DataB(cborObj.buffer); | ||
// if indefinite length (> 64) | ||
// `bytes` property already concats the chunks for us | ||
return new DataB_1.DataB(cborObj.bytes); | ||
} | ||
@@ -22,0 +24,0 @@ if (cborObj instanceof cbor_1.CborArray) { |
@@ -12,2 +12,5 @@ "use strict"; | ||
var assert_1 = require("./utils/assert.js"); | ||
var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils"); | ||
var minBigInt = BigInt("-18446744073709551616"); // -(2n ** 64n) | ||
var maxBigInt = BigInt("18446744073709551615"); // (2n ** 64n) - 1n | ||
function dataToCborObj(data) { | ||
@@ -58,3 +61,19 @@ (0, assert_1.assert)((0, Data_1.isData)(data), "Invalid data; cannot convert to CBOR"); | ||
if (data instanceof DataB_1.DataB) { | ||
return new cbor_1.CborBytes(data.bytes.toBuffer()); | ||
var bytes = data.bytes.toBuffer(); | ||
// definite length only if length <= 64 | ||
if (bytes.length <= 64) | ||
return new cbor_1.CborBytes(bytes); | ||
var ptr = 64; | ||
var fst = Uint8Array.prototype.slice.call(bytes, 0, ptr); | ||
var chunks = []; | ||
var chunkSize = 0; | ||
var chunkEnd = 0; | ||
while (ptr < bytes.length) { | ||
chunkSize = Math.min(64, bytes.length - ptr); | ||
chunkEnd = ptr + chunkSize; | ||
chunks.push(Uint8Array.prototype.slice.call(bytes, ptr, chunkEnd)); | ||
ptr = chunkEnd; | ||
} | ||
// indefinite length bytes | ||
return new cbor_1.CborBytes(fst, chunks); | ||
} | ||
@@ -68,1 +87,5 @@ throw new Error("'dataToCborObj' did not match any possible Data constructor"); | ||
exports.dataToCbor = dataToCbor; | ||
function positiveIntegerToBytes(n) { | ||
var hex = n.toString(16); | ||
return (0, uint8array_utils_1.fromHex)((hex.length % 2) === 0 ? hex : "0" + hex); | ||
} |
{ | ||
"name": "@harmoniclabs/plutus-data", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -38,7 +38,8 @@ "main": "./dist/index.js", | ||
"@harmoniclabs/biguint": "^1.0.0", | ||
"@harmoniclabs/crypto": "^0.2.0" | ||
"@harmoniclabs/crypto": "^0.2.0", | ||
"@harmoniclabs/uint8array-utils": "^1.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@harmoniclabs/bytestring": "^1.0.0", | ||
"@harmoniclabs/cbor": "^1.2.0" | ||
"@harmoniclabs/cbor": "^1.3.0" | ||
}, | ||
@@ -45,0 +46,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36613
936
5