Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps(dev): bump aegir from 43.0.3 to 44.1.1 #306

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# multiformats

[![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io)
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multiformats.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multiformats)
[![CI](https://img.shields.io/github/actions/workflow/status/multiformats/js-multiformats/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/multiformats/js-multiformats/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
Expand Down Expand Up @@ -212,7 +214,7 @@ $ npm i multiformats

## Browser `<script>` tag

Loading this module through a script tag will make it's exports available as `Multiformats` in the global namespace.
Loading this module through a script tag will make its exports available as `Multiformats` in the global namespace.

```html
<script src="https://unpkg.com/multiformats/dist/index.min.js"></script>
Expand All @@ -226,8 +228,8 @@ Loading this module through a script tag will make it's exports available as `Mu

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
- Apache 2.0, ([LICENSE-APACHE](https://github.com/multiformats/js-multiformats/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/multiformats/js-multiformats/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribution

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"bugs": {
"url": "https://github.com/multiformats/js-multiformats/issues"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"keywords": [
"ipfs",
"ipld",
Expand Down Expand Up @@ -275,7 +279,7 @@
"@stablelib/sha256": "^2.0.0",
"@stablelib/sha512": "^2.0.0",
"@types/node": "^22.0.0",
"aegir": "^43.0.1",
"aegir": "^44.1.1",
"buffer": "^6.0.3",
"cids": "^1.1.9",
"crypto-hash": "^3.0.0"
Expand Down
5 changes: 3 additions & 2 deletions src/bases/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ class Decoder<Base extends string, Prefix extends string> implements MultibaseDe
constructor (name: Base, prefix: Prefix, baseDecode: DecodeFn) {
this.name = name
this.prefix = prefix
const prefixCodePoint = prefix.codePointAt(0)
/* c8 ignore next 3 */
if (prefix.codePointAt(0) === undefined) {
if (prefixCodePoint === undefined) {
throw new Error('Invalid prefix character')
}
this.prefixCodePoint = prefix.codePointAt(0) as number
this.prefixCodePoint = prefixCodePoint
this.baseDecode = baseDecode
}

Expand Down
17 changes: 14 additions & 3 deletions src/bases/base256emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

const alphabet = Array.from('🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂')
const alphabetBytesToChars: string[] = (alphabet.reduce<string[]>((p, c, i) => { p[i] = c; return p }, ([])))
const alphabetCharsToBytes: number[] = (alphabet.reduce<number[]>((p, c, i) => { p[c.codePointAt(0) as number] = i; return p }, ([])))
const alphabetCharsToBytes: number[] = (alphabet.reduce<number[]>((p, c, i) => {
const codePoint = c.codePointAt(0)
if (codePoint == null) {
throw new Error(`Invalid character: ${c}`)
}

Check warning on line 9 in src/bases/base256emoji.ts

View check run for this annotation

Codecov / codecov/patch

src/bases/base256emoji.ts#L8-L9

Added lines #L8 - L9 were not covered by tests
p[codePoint] = i
return p
}, ([])))

function encode (data: Uint8Array): string {
return data.reduce((p, c) => {
Expand All @@ -14,8 +21,12 @@
function decode (str: string): Uint8Array {
const byts = []
for (const char of str) {
const byt = alphabetCharsToBytes[char.codePointAt(0) as number]
if (byt === undefined) {
const codePoint = char.codePointAt(0)
if (codePoint == null) {
throw new Error(`Invalid character: ${char}`)
}

Check warning on line 27 in src/bases/base256emoji.ts

View check run for this annotation

Codecov / codecov/patch

src/bases/base256emoji.ts#L26-L27

Added lines #L26 - L27 were not covered by tests
const byt = alphabetCharsToBytes[codePoint]
if (byt == null) {
throw new Error(`Non-base256emoji character: ${char}`)
}
byts.push(byt)
Expand Down
1 change: 1 addition & 0 deletions src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ type CreateUnsafeInput <T, Code extends number, Alg extends number, V extends AP
* @template V - CID version
*/
export function createUnsafe <T, Code extends number, Alg extends number, V extends API.Version> ({ bytes, cid, value: maybeValue, codec }: CreateUnsafeInput<T, Code, Alg, V>): API.BlockView<T, Code, Alg, V> {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const value = maybeValue !== undefined
? maybeValue
: (codec?.decode(bytes))
Expand Down
25 changes: 14 additions & 11 deletions test/test-cid.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* globals describe, it */
/* eslint-disable @typescript-eslint/strict-boolean-expressions */

import { assert } from 'aegir/chai'
import OLDCID from 'cids'
Expand Down Expand Up @@ -104,8 +105,8 @@ describe('CID', () => {
it('should construct from an old CID', () => {
const cidStr = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
const oldCid = CID.parse(cidStr)
const newCid = (CID.asCID(oldCid) as CID)
assert.deepStrictEqual(newCid.toString(), cidStr)
const newCid = CID.asCID(oldCid)
assert.deepStrictEqual(newCid?.toString(), cidStr)
})

it('inspect bytes', () => {
Expand Down Expand Up @@ -225,8 +226,8 @@ describe('CID', () => {
const cidStr =
'bafybeidskjjd4zmr7oh6ku6wp72vvbxyibcli2r6if3ocdcy7jjjusvl2u'
const oldCid = CID.parse(cidStr)
const newCid = (CID.asCID(oldCid) as CID)
assert.deepStrictEqual(newCid.toString(), cidStr)
const newCid = CID.asCID(oldCid)
assert.deepStrictEqual(newCid?.toString(), cidStr)
})

it('.link() should return this CID', () => {
Expand Down Expand Up @@ -515,7 +516,7 @@ describe('CID', () => {
// @ts-expect-error - no such method
assert.strictEqual(typeof incompatibleCID.toV0, 'undefined')

const cid1 = (CID.asCID(incompatibleCID) as CID)
const cid1 = CID.asCID(incompatibleCID)
assert.ok(cid1 instanceof CID)
assert.strictEqual(cid1.code, code)
assert.strictEqual(cid1.version, version)
Expand All @@ -537,7 +538,7 @@ describe('CID', () => {
assert.strictEqual(cid3, cid4)

const cid5 = (
CID.asCID(new OLDCID(1, 'raw', Uint8Array.from(hash.bytes))) as CID
CID.asCID(new OLDCID(1, 'raw', Uint8Array.from(hash.bytes)))
)
assert.ok(cid5 instanceof CID)
assert.strictEqual(cid5.version, 1)
Expand All @@ -556,7 +557,9 @@ describe('CID', () => {
assert.deepStrictEqual({ ...x, ...empty }, { ...y, ...empty })
}

const equalDigest = (x: MultihashDigest, y: MultihashDigest): void => {
const equalDigest = (x?: MultihashDigest, y?: MultihashDigest): void => {
assert.ok(x)
assert.ok(y)
assert.deepStrictEqual(x.digest, y.digest)
assert.deepStrictEqual(x.code, y.code)
assert.deepStrictEqual(x.digest, y.digest)
Expand Down Expand Up @@ -653,12 +656,12 @@ describe('CID', () => {
it('new CID from old CID', async () => {
const hash = await sha256.digest(textEncoder.encode('abc'))
const cid = (
CID.asCID(new OLDCID(1, 'raw', Uint8Array.from(hash.bytes))) as CID
CID.asCID(new OLDCID(1, 'raw', Uint8Array.from(hash.bytes)))
)
assert.deepStrictEqual(cid.version, 1)
assert.deepStrictEqual(cid?.version, 1)

equalDigest(cid.multihash, hash)
assert.deepStrictEqual(cid.code, 85)
equalDigest(cid?.multihash, hash)
assert.deepStrictEqual(cid?.code, 85)
})

it('util.inspect', async () => {
Expand Down
15 changes: 8 additions & 7 deletions test/test-link.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* globals describe, it */
/* eslint-disable @typescript-eslint/strict-boolean-expressions */

import { assert } from 'aegir/chai'
import { sha256 } from '../src/hashes/sha2.js'
Expand All @@ -25,10 +26,10 @@ describe('Link', () => {
it('create v1', async () => {
const hash = await sha256.digest(utf8.encode('abc'))
const link = Link.create(0x71, hash)
const code = link.code as 0x71
const code = link.code
assert.deepStrictEqual(code, 0x71)

const version = link.version as 1
const version = link.version
assert.deepEqual(version, 1)

const multihash = link.multihash
Expand All @@ -39,10 +40,10 @@ describe('Link', () => {
const hash = await sha256.digest(utf8.encode('abc'))
const link = Link.createLegacy(hash)

const code = link.code as 0x70
const code = link.code
assert.deepStrictEqual(code, 0x70)

const version = link.version as 0
const version = link.version
assert.deepEqual(version, 0)

const multihash = link.multihash
Expand Down Expand Up @@ -72,7 +73,7 @@ describe('Link', () => {
const t1 = link
assert.ok(t1)

// ensurate that you can't cast incorrectly
// ensure that you can't cast incorrectly
const t2 =
// @ts-expect-error - version is 1 not 0
(link as Link.Link<unknown, typeof CBOR, typeof SHA256, 0>)
Expand Down Expand Up @@ -124,10 +125,10 @@ describe('decode', () => {

const link = Link.decode(bytes)

const code = link.code as 0x71
const code = link.code
assert.deepStrictEqual(code, 0x71)

const version = link.version as 1
const version = link.version
assert.deepEqual(version, 1)

const multihash = link.multihash
Expand Down
4 changes: 2 additions & 2 deletions test/test-multibase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ describe('multibase', () => {
})

it('infers prefix and name corretly', () => {
const name = base32.name as 'base32'
const name = base32.name

// @ts-expect-error - TS catches mismatch
const name2: 'base16' = base32.name

const prefix = base32.prefix as 'b'
const prefix = base32.prefix
assert.equal(prefix, 'b')
assert.equal(name, 'base32')
assert.equal(name2, name)
Expand Down
Loading