Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
A modular, composable, strongly typed and lightweight implementation of the [SCALE Codec](https://docs.substrate.io/v3/advanced/scale-ts/)
A modular, composable, strongly typed and lightweight implementation of the SCALE Codec
npm install --save scale-ts
import { bool, _void, str, u32, Enum, Struct, Vector } from "scale-ts"
const myCodec = Struct({
id: u32,
name: str,
friendIds: Vector(u32),
event: Enum({
_void,
one: str,
many: Vector(str),
allOrNothing: bool,
}),
})
/*
Something really cool about this library is that by having composable codecs
which have very good typings, then the inferred types of the resulting codecs
also have really good typings. For instance, the inferred types of codec
defined above are:
*/
type MyCodec = Codec<{
id: number;
name: string;
friendIds: number[];
event:
| { tag: _void; value?: undefined };
| { tag: one; value: string; }
| { tag: many; value: string[]; }
| { tag: allOrNothing; value: boolean; };
}>
*/
Therefore, we won't get typing errors as long as we pass a valide interface
to the encoder:
const encodedData: ArrayBuffer = myCodec.enc({
event: { tag: 'allOrNothing', value: true },
name: "Some name",
id: 100,
friendIds: [1, 2, 3],
})
console.log(bufferToHex(encodedData))
// => 0x6400000024536f6d65206e616d650c0100000002000000030000000201
const decodedData = myCodec.dec(encodedData)
// also possible:
// const decodedData = myCodec.dec("0x6400000024536f6d65206e616d650c0100000002000000030000000201")
console.log(JSON.stringify(decodedData, null, 2))
// =>
//{
// "id": 100,
// "name": "Some name",
// "friendIds": [
// 1,
// 2,
// 3
// ],
// "event": {
// "tag": "allOrNothing",
// "value": true
// }
//}
In this library you won't find common definitions like AccountId
. However,
since the definitions of this library are enhanceable and composable, it's
very easy to create new custom definitions. For instance, the implementation of
the bool
Codec looks like this:
import { enhanceCodec, u8, Codec } from "../"
const booleanToNumber = (value: boolean) => (value ? 1 : 0)
export const bool: Codec<boolean> = enhanceCodec(u8, booleanToNumber, Boolean)
Similarly, you could implement any other definitions are that based on other
definitions. For instance, a possible implementation of an AccountId
definition could be:
import { enhanceCodec, Bytes } from "scale-ts"
import { decodeAddress, encodeAddress } from "@polkadot/util-crypto"
export const AccountId = enhanceCodec(Bytes(32), decodeAddress, encodeAddress)
bool.enc(false)
// => 0x00
bool.dec("0x01")
// => true
Sometimes, mainly when creating your custom codecs, it's usefull to have a
codec that simply reads/writes a certain amount of bytes. For example, see the
example above for creating a custom AccountId
codec.
const threeBytes = Bytes(3)
threeBytes.enc(new Uint8Array([0, 15, 255]))
// => 0x000fff
bool.dec("0x000fff00")
// => 0x000fff
Supported codecs are: compact
, u8
, u16
, u32
, u64
, u128
, i8
, i16
,
i32
, i64
, i128
compact.enc(65535)
// => 0xfeff0300
compact.dec("0xfeff0300")
// => 65535
i128.enc(-18676936063680574795862633153229949450n)
// => 0xf6f5f4f3f2f1f0f9f8f7f6f5f4f3f2f1
i128.dec("0xf6f5f4f3f2f1f0f9f8f7f6f5f4f3f2f1")
// => -18676936063680574795862633153229949450n
FAQs
A modular, composable, strongly typed and lightweight implementation of the [SCALE Codec](https://docs.substrate.io/v3/advanced/scale-codec/)
The npm package scale-ts receives a total of 33,849 weekly downloads. As such, scale-ts popularity was classified as popular.
We found that scale-ts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.