Socket
Socket
Sign inDemoInstall

ssb-uri2

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssb-uri2 - npm Package Compare versions

Comparing version 1.9.0 to 2.0.0

12

lib/index.d.ts
import { BlobId, FeedId, MsgId } from 'ssb-typescript';
declare type FeedTF = ['feed', 'ed25519'] | ['feed', 'bendybutt-v1'] | ['feed', 'gabbygrove-v1'] | ['feed', 'buttwoo-v1'];
declare type MessageTF = ['message', 'sha256'] | ['message', 'bendybutt-v1'] | ['message', 'gabbygrove-v1'] | ['message', 'buttwoo-v1'];
declare type BlobTF = ['blob', 'sha256'];
declare type FeedTF = ['feed', 'classic'] | ['feed', 'ed25519'] | ['feed', 'bendybutt-v1'] | ['feed', 'gabbygrove-v1'] | ['feed', 'buttwoo-v1'];
declare type MessageTF = ['message', 'classic'] | ['message', 'sha256'] | ['message', 'bendybutt-v1'] | ['message', 'gabbygrove-v1'] | ['message', 'buttwoo-v1'];
declare type BlobTF = ['blob', 'classic'] | ['blob', 'sha256'];
declare type AddressTF = ['address', 'multiserver'];

@@ -17,11 +17,11 @@ declare type EncryptionKeyTF = ['encryption-key', 'box2-dm-dh'];

export declare function toMultiserverAddress(uri: string): string | null;
export declare function isFeedSSBURI(uri: string | null): boolean;
export declare function isClassicFeedSSBURI(uri: string | null): boolean;
export declare function isBendyButtV1FeedSSBURI(uri: string | null): boolean;
export declare function isGabbyGroveV1FeedSSBURI(uri: string | null): boolean;
export declare function isButtwooV1FeedSSBURI(uri: string | null): boolean;
export declare function isMessageSSBURI(uri: string | null): boolean;
export declare function isClassicMessageSSBURI(uri: string | null): boolean;
export declare function isBendyButtV1MessageSSBURI(uri: string | null): boolean;
export declare function isGabbyGroveV1MessageSSBURI(uri: string | null): boolean;
export declare function isButtwooV1MessageSSBURI(uri: string | null): boolean;
export declare function isBlobSSBURI(uri: string | null): boolean;
export declare function isClassicBlobSSBURI(uri: string | null): boolean;
export declare function isAddressSSBURI(uri: string | null): boolean;

@@ -28,0 +28,0 @@ export declare function isEncryptionKeyBox2DMDiffieHellmanSSBURI(uri: string | null): boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decompose = exports.compose = exports.getMessageSSBURIRegex = exports.getFeedSSBURIRegex = exports.isSSBURI = exports.isExperimentalSSBURIWithAction = exports.isExperimentalSSBURI = exports.isIdentityFusionSSBURI = exports.isIdentityPOBoxSSBURI = exports.isEncryptionKeyBox2DMDiffieHellmanSSBURI = exports.isAddressSSBURI = exports.isBlobSSBURI = exports.isButtwooV1MessageSSBURI = exports.isGabbyGroveV1MessageSSBURI = exports.isBendyButtV1MessageSSBURI = exports.isMessageSSBURI = exports.isButtwooV1FeedSSBURI = exports.isGabbyGroveV1FeedSSBURI = exports.isBendyButtV1FeedSSBURI = exports.isFeedSSBURI = exports.toMultiserverAddress = exports.toBlobSigil = exports.toMessageSigil = exports.toFeedSigil = exports.fromMultiserverAddress = exports.fromBlobSigil = exports.fromMessageSigil = exports.fromFeedSigil = void 0;
exports.decompose = exports.compose = exports.getMessageSSBURIRegex = exports.getFeedSSBURIRegex = exports.isSSBURI = exports.isExperimentalSSBURIWithAction = exports.isExperimentalSSBURI = exports.isIdentityFusionSSBURI = exports.isIdentityPOBoxSSBURI = exports.isEncryptionKeyBox2DMDiffieHellmanSSBURI = exports.isAddressSSBURI = exports.isClassicBlobSSBURI = exports.isButtwooV1MessageSSBURI = exports.isGabbyGroveV1MessageSSBURI = exports.isBendyButtV1MessageSSBURI = exports.isClassicMessageSSBURI = exports.isButtwooV1FeedSSBURI = exports.isGabbyGroveV1FeedSSBURI = exports.isBendyButtV1FeedSSBURI = exports.isClassicFeedSSBURI = exports.toMultiserverAddress = exports.toBlobSigil = exports.toMessageSigil = exports.toFeedSigil = exports.fromMultiserverAddress = exports.fromBlobSigil = exports.fromMessageSigil = exports.fromFeedSigil = void 0;
const Base64 = {

@@ -23,3 +23,3 @@ unsafeToSafe(input) {

const data = Base64.unsafeToSafe(sigil.slice(1, -8));
return `ssb:feed/ed25519/${data}`;
return `ssb:feed/classic/${data}`;
}

@@ -29,3 +29,3 @@ exports.fromFeedSigil = fromFeedSigil;

const data = Base64.unsafeToSafe(sigil.slice(1, -7));
return `ssb:message/sha256/${data}`;
return `ssb:message/classic/${data}`;
}

@@ -35,3 +35,3 @@ exports.fromMessageSigil = fromMessageSigil;

const data = Base64.unsafeToSafe(sigil.slice(1, -7));
return `ssb:blob/sha256/${data}`;
return `ssb:blob/classic/${data}`;
}

@@ -45,3 +45,3 @@ exports.fromBlobSigil = fromBlobSigil;

function toFeedSigil(uri) {
if (!isFeedSSBURI(uri))
if (!isClassicFeedSSBURI(uri))
return null;

@@ -55,3 +55,3 @@ const base64Data = extractBase64Data(new URL(uri).pathname);

function toMessageSigil(uri) {
if (!isMessageSSBURI(uri))
if (!isClassicMessageSSBURI(uri))
return null;

@@ -65,2 +65,4 @@ const base64Data = extractBase64Data(new URL(uri).pathname);

function toBlobSigil(uri) {
if (!isClassicBlobSSBURI(uri))
return null;
const base64Data = extractBase64Data(new URL(uri).pathname);

@@ -85,6 +87,7 @@ if (!base64Data)

}
function isFeedSSBURI(uri) {
return checkTypeFormat(uri, 'feed', 'ed25519');
function isClassicFeedSSBURI(uri) {
return (checkTypeFormat(uri, 'feed', 'classic') ||
checkTypeFormat(uri, 'feed', 'ed25519'));
}
exports.isFeedSSBURI = isFeedSSBURI;
exports.isClassicFeedSSBURI = isClassicFeedSSBURI;
function isBendyButtV1FeedSSBURI(uri) {

@@ -102,6 +105,7 @@ return checkTypeFormat(uri, 'feed', 'bendybutt-v1');

exports.isButtwooV1FeedSSBURI = isButtwooV1FeedSSBURI;
function isMessageSSBURI(uri) {
return checkTypeFormat(uri, 'message', 'sha256');
function isClassicMessageSSBURI(uri) {
return (checkTypeFormat(uri, 'message', 'classic') ||
checkTypeFormat(uri, 'message', 'sha256'));
}
exports.isMessageSSBURI = isMessageSSBURI;
exports.isClassicMessageSSBURI = isClassicMessageSSBURI;
function isBendyButtV1MessageSSBURI(uri) {

@@ -119,6 +123,7 @@ return checkTypeFormat(uri, 'message', 'bendybutt-v1');

exports.isButtwooV1MessageSSBURI = isButtwooV1MessageSSBURI;
function isBlobSSBURI(uri) {
return checkTypeFormat(uri, 'blob', 'sha256');
function isClassicBlobSSBURI(uri) {
return (checkTypeFormat(uri, 'blob', 'classic') ||
checkTypeFormat(uri, 'blob', 'sha256'));
}
exports.isBlobSSBURI = isBlobSSBURI;
exports.isClassicBlobSSBURI = isClassicBlobSSBURI;
function isAddressSSBURI(uri) {

@@ -161,11 +166,11 @@ if (!uri)

function isSSBURI(uri) {
return (isFeedSSBURI(uri) ||
return (isClassicFeedSSBURI(uri) ||
isBendyButtV1FeedSSBURI(uri) ||
isGabbyGroveV1FeedSSBURI(uri) ||
isButtwooV1FeedSSBURI(uri) ||
isMessageSSBURI(uri) ||
isClassicMessageSSBURI(uri) ||
isBendyButtV1MessageSSBURI(uri) ||
isGabbyGroveV1MessageSSBURI(uri) ||
isButtwooV1MessageSSBURI(uri) ||
isBlobSSBURI(uri) ||
isClassicBlobSSBURI(uri) ||
isAddressSSBURI(uri) ||

@@ -181,2 +186,3 @@ isEncryptionKeyBox2DMDiffieHellmanSSBURI(uri) ||

const formatsWith3Parts = [
'classic',
'ed25519',

@@ -203,2 +209,3 @@ 'bendybutt-v1',

const format = [
'classic',
'sha256',

@@ -215,15 +222,16 @@ 'bendybutt-v1',

exports.getMessageSSBURIRegex = getMessageSSBURIRegex;
function validateParts(parts) {
if (!parts.type)
function validateParts({ type, format, data }) {
if (!type)
throw new Error('Missing required "type" property');
if (!parts.format)
if (!format)
throw new Error('Missing required "format" property');
if (!parts.data)
if (!data)
throw new Error('Missing required "data" property');
if (parts.type === 'feed') {
if (parts.format !== 'ed25519' &&
parts.format !== 'bendybutt-v1' &&
parts.format !== 'gabbygrove-v1' &&
parts.format !== 'buttwoo-v1') {
throw new Error('Unknown format for type "feed": ' + parts.format);
if (type === 'feed') {
if (format !== 'classic' &&
format !== 'ed25519' &&
format !== 'bendybutt-v1' &&
format !== 'gabbygrove-v1' &&
format !== 'buttwoo-v1') {
throw new Error('Unknown format for type "feed": ' + format);
}

@@ -233,8 +241,9 @@ else

}
if (parts.type === 'message') {
if (parts.format !== 'sha256' &&
parts.format !== 'bendybutt-v1' &&
parts.format !== 'gabbygrove-v1' &&
parts.format !== 'buttwoo-v1') {
throw new Error('Unknown format for type "message": ' + parts.format);
if (type === 'message') {
if (format !== 'classic' &&
format !== 'sha256' &&
format !== 'bendybutt-v1' &&
format !== 'gabbygrove-v1' &&
format !== 'buttwoo-v1') {
throw new Error('Unknown format for type "message": ' + format);
}

@@ -244,5 +253,5 @@ else

}
if (parts.type === 'blob') {
if (parts.format !== 'sha256') {
throw new Error('Unknown format for type "blob": ' + parts.format);
if (type === 'blob') {
if (format !== 'classic' && format !== 'sha256') {
throw new Error('Unknown format for type "blob": ' + format);
}

@@ -252,5 +261,5 @@ else

}
if (parts.type === 'address') {
if (parts.format !== 'multiserver') {
throw new Error('Unknown format for type "address": ' + parts.format);
if (type === 'address') {
if (format !== 'multiserver') {
throw new Error('Unknown format for type "address": ' + format);
}

@@ -260,5 +269,5 @@ else

}
if (parts.type === 'encryption-key') {
if (parts.format !== 'box2-dm-dh') {
throw new Error('Unknown format for type "encryption-key": ' + parts.format);
if (type === 'encryption-key') {
if (format !== 'box2-dm-dh') {
throw new Error('Unknown format for type "encryption-key": ' + format);
}

@@ -268,5 +277,5 @@ else

}
if (parts.type === 'identity') {
if (parts.format !== 'po-box' && parts.format !== 'fusion') {
throw new Error('Unknown format for type "identity": ' + parts.format);
if (type === 'identity') {
if (format !== 'po-box' && format !== 'fusion') {
throw new Error('Unknown format for type "identity": ' + format);
}

@@ -277,2 +286,17 @@ else

}
function fixParts(parts) {
const { type, format } = parts;
if (type === 'feed' && format === 'ed25519') {
parts.format = 'classic';
return;
}
if (type === 'message' && format === 'sha256') {
parts.format = 'classic';
return;
}
if (type === 'blob' && format === 'sha256') {
parts.format = 'classic';
return;
}
}
function compose(parts) {

@@ -300,2 +324,3 @@ validateParts(parts);

validateParts(parts);
fixParts(parts);
if (safeExtraData)

@@ -302,0 +327,0 @@ parts.extraData = Base64.safeToUnsafe(safeExtraData);

{
"name": "ssb-uri2",
"version": "1.9.0",
"version": "2.0.0",
"description": "Utilities for recognizing and converting SSB URIs",

@@ -40,3 +40,3 @@ "repository": {

},
"readme": "# ssb-uri2\n\n> An SSB utility library for handling and converting SSB URIs\n\nThis library provides utilities that recognize SSB URIs according to the [spec](https://github.com/ssb-ngi-pointer/ssb-uri-spec), and is compatible with [ssb-uri](https://github.com/fraction/ssb-uri) (prior work), while adding more support and more utilities.\n\n## Install\n\n```\nnpm install ssb-uri2\n```\n\n## Example\n\n```js\nconst ssbUri = require('ssb-uri2');\n\nconst exampleURI =\n 'ssb:message/sha256/g3hPVPDEO1Aj_uPl0-J2NlhFB2bbFLIHlty-YuqFZ3w=';\n\nssbUri.isMessageSSBURI(exampleURI);\n// true\n\nssbUri.toMessageSigil(exampleURI);\n// '%g3hPVPDEO1Aj/uPl0+J2NlhFB2bbFLIHlty+YuqFZ3w=.sha256'\n```\n\n## Boolean APIs\n\n### `isSSBURI(uri: string | uri): boolean`\n\n### `isFeedSSBURI(uri: string | null): boolean`\n\n### `isBendyButtV1FeedSSBURI(uri: string | null): boolean`\n\n### `isGabbyGroveV1FeedSSBURI(uri: string | null): boolean`\n\n### `isMessageSSBURI(uri: string | null): boolean`\n\n### `isBendyButtV1MessageSSBURI(uri: string | null): boolean`\n\n### `isGabbyGroveV1MessageSSBURI(uri: string | null): boolean`\n\n### `isBlobSSBURI(uri: string | null): boolean`\n\n### `isAddressSSBURI(uri: string | null): boolean`\n\n### `isEncryptionKeyBox2DMDiffieHellmanSSBURI(uri: string | null): boolean`\n\n### `isIdentityPOBoxSSBURI(uri: string | null): boolean`\n\n### `isIdentityFusionSSBURI(uri: string | null): boolean`\n\n### `isExperimentalSSBURI(uri: string | null): boolean`\n\n### `isExperimentalSSBURIWithAction(action: string): (uri: string) => boolean`\n\n## Regular Expressions\n\n### `getFeedSSBURIRegex() => RegExp`\n\n### `getMessageSSBURIRegex() => RegExp`\n\n## Conversion APIs\n\n### `fromFeedSigil(sigil: string): string`\n\n### `fromMessageSigil(sigil: string): string`\n\n### `fromBlobSigil(sigil: string): string`\n\n### `fromMultiserverAddress(msaddr: string): string`\n\n### `toFeedSigil(uri: string): string | null`\n\n### `toMessageSigil(uri: string): string | null`\n\n### `toBlobSigil(uri: string): string | null`\n\n### `toMultiserverAddress(uri: string): string | null`\n\n### `compose(parts: {type, format, data, extraData}): string`\n\n### `decompose(uri: string): {type, format, data, extraData}`\n\nThe object `{type, format, data}` is such that it matches `ssb:${type}/${format}/${data}`, except the `data` is always in normal Base64 (i.e. **not** URI safe).\n\nThere is also the case of `extraData` for special URIs such as `ssb:feed/buttwoo-v1/${data}/${extraData}`.\n\n## License\n\nLGPL-3.0\n"
"readme": "# ssb-uri2\n\n> An SSB utility library for handling and converting SSB URIs\n\nThis library provides utilities that recognize SSB URIs according to the [spec](https://github.com/ssb-ngi-pointer/ssb-uri-spec), and is compatible with [ssb-uri](https://github.com/fraction/ssb-uri) (prior work), while adding more support and more utilities.\n\n## Install\n\n```\nnpm install ssb-uri2\n```\n\n## Example\n\n```js\nconst ssbUri = require('ssb-uri2');\n\nconst exampleURI =\n 'ssb:message/classic/g3hPVPDEO1Aj_uPl0-J2NlhFB2bbFLIHlty-YuqFZ3w=';\n\nssbUri.isClassicMessageSSBURI(exampleURI);\n// true\n\nssbUri.toMessageSigil(exampleURI);\n// '%g3hPVPDEO1Aj/uPl0+J2NlhFB2bbFLIHlty+YuqFZ3w=.sha256'\n```\n\n## Boolean APIs\n\n### `isSSBURI(uri: string | uri): boolean`\n\n### `isClassicFeedSSBURI(uri: string | null): boolean`\n\n### `isBendyButtV1FeedSSBURI(uri: string | null): boolean`\n\n### `isGabbyGroveV1FeedSSBURI(uri: string | null): boolean`\n\n### `isClassicMessageSSBURI(uri: string | null): boolean`\n\n### `isBendyButtV1MessageSSBURI(uri: string | null): boolean`\n\n### `isGabbyGroveV1MessageSSBURI(uri: string | null): boolean`\n\n### `isClassicBlobSSBURI(uri: string | null): boolean`\n\n### `isAddressSSBURI(uri: string | null): boolean`\n\n### `isEncryptionKeyBox2DMDiffieHellmanSSBURI(uri: string | null): boolean`\n\n### `isIdentityPOBoxSSBURI(uri: string | null): boolean`\n\n### `isIdentityFusionSSBURI(uri: string | null): boolean`\n\n### `isExperimentalSSBURI(uri: string | null): boolean`\n\n### `isExperimentalSSBURIWithAction(action: string): (uri: string) => boolean`\n\n## Regular Expressions\n\n### `getFeedSSBURIRegex() => RegExp`\n\n### `getMessageSSBURIRegex() => RegExp`\n\n## Conversion APIs\n\n### `fromFeedSigil(sigil: string): string`\n\n### `fromMessageSigil(sigil: string): string`\n\n### `fromBlobSigil(sigil: string): string`\n\n### `fromMultiserverAddress(msaddr: string): string`\n\n### `toFeedSigil(uri: string): string | null`\n\n### `toMessageSigil(uri: string): string | null`\n\n### `toBlobSigil(uri: string): string | null`\n\n### `toMultiserverAddress(uri: string): string | null`\n\n### `compose(parts: {type, format, data, extraData}): string`\n\n### `decompose(uri: string): {type, format, data, extraData}`\n\nThe object `{type, format, data}` is such that it matches `ssb:${type}/${format}/${data}`, except the `data` is always in normal Base64 (i.e. **not** URI safe).\n\nThere is also the case of `extraData` for special URIs such as `ssb:feed/buttwoo-v1/${data}/${extraData}`.\n\n## License\n\nLGPL-3.0\n"
}

@@ -19,5 +19,5 @@ # ssb-uri2

const exampleURI =
'ssb:message/sha256/g3hPVPDEO1Aj_uPl0-J2NlhFB2bbFLIHlty-YuqFZ3w=';
'ssb:message/classic/g3hPVPDEO1Aj_uPl0-J2NlhFB2bbFLIHlty-YuqFZ3w=';
ssbUri.isMessageSSBURI(exampleURI);
ssbUri.isClassicMessageSSBURI(exampleURI);
// true

@@ -33,3 +33,3 @@

### `isFeedSSBURI(uri: string | null): boolean`
### `isClassicFeedSSBURI(uri: string | null): boolean`

@@ -40,3 +40,3 @@ ### `isBendyButtV1FeedSSBURI(uri: string | null): boolean`

### `isMessageSSBURI(uri: string | null): boolean`
### `isClassicMessageSSBURI(uri: string | null): boolean`

@@ -47,3 +47,3 @@ ### `isBendyButtV1MessageSSBURI(uri: string | null): boolean`

### `isBlobSSBURI(uri: string | null): boolean`
### `isClassicBlobSSBURI(uri: string | null): boolean`

@@ -50,0 +50,0 @@ ### `isAddressSSBURI(uri: string | null): boolean`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc