Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 2.0.0 to 2.0.1

13

lib/index.d.ts
import { BlobId, FeedId, MsgId } from 'ssb-typescript';
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 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 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 isClassicFeedSSBURI(uri: string | null): boolean;
export declare function isFeedSSBURI(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 isClassicMessageSSBURI(uri: string | null): boolean;
export declare function isMessageSSBURI(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 isClassicBlobSSBURI(uri: string | null): boolean;
export declare function isBlobSSBURI(uri: string | null): boolean;
export declare function isAddressSSBURI(uri: string | null): boolean;

@@ -40,3 +40,2 @@ export declare function isEncryptionKeyBox2DMDiffieHellmanSSBURI(uri: string | null): boolean;

data: string;
extraData?: string;
};

@@ -43,0 +42,0 @@ declare type CanonicalParts = PartsFor<FeedTF> | PartsFor<MessageTF> | PartsFor<BlobTF> | PartsFor<AddressTF> | PartsFor<EncryptionKeyTF> | PartsFor<IdentityTF>;

"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.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;
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;
const Base64 = {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@@ -185,20 +180,7 @@ isEncryptionKeyBox2DMDiffieHellmanSSBURI(uri) ||

const type = 'feed';
const formatsWith3Parts = [
'classic',
'ed25519',
'bendybutt-v1',
'gabbygrove-v1',
'buttwoo-v1',
];
const formatsWith4Parts = ['buttwoo-v1'];
const ruleWith3 = `ssb:(\/\/)?` +
const format = ['ed25519', 'bendybutt-v1', 'gabbygrove-v1', 'buttwoo-v1'];
return new RegExp(`ssb:(\/\/)?` +
`${type}(\/|:)` +
`(${formatsWith3Parts.join('|')})(\/|:)` +
`[a-zA-Z0-9_\-]{43}=`;
const ruleWith4 = `ssb:(\/\/)?` +
`${type}(\/|:)` +
`(${formatsWith4Parts.join('|')})(\/|:)` +
`[a-zA-Z0-9_\-]{43}=(\/|:)` +
`[a-zA-Z0-9_\-]{43}=`;
return new RegExp(`(${ruleWith4}|${ruleWith3})`);
`(${format.join('|')})(\/|:)` +
`[a-zA-Z0-9_\-]{43}=`);
}

@@ -209,7 +191,6 @@ exports.getFeedSSBURIRegex = getFeedSSBURIRegex;

const format = [
'classic',
'sha256',
'bendybutt-v1',
'gabbygrove-v1',
'buttwoo-v1',
'buttwoo-v1'
];

@@ -222,16 +203,15 @@ return new RegExp(`ssb:(\/\/)?` +

exports.getMessageSSBURIRegex = getMessageSSBURIRegex;
function validateParts({ type, format, data }) {
if (!type)
function validateParts(parts) {
if (!parts.type)
throw new Error('Missing required "type" property');
if (!format)
if (!parts.format)
throw new Error('Missing required "format" property');
if (!data)
if (!parts.data)
throw new Error('Missing required "data" property');
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);
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);
}

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

}
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);
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);
}

@@ -253,5 +232,5 @@ else

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

@@ -261,5 +240,5 @@ else

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

@@ -269,5 +248,5 @@ else

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

@@ -277,5 +256,5 @@ else

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

@@ -286,28 +265,6 @@ 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) {
validateParts(parts);
const { type, format, data, extraData } = parts;
const safeData = Base64.unsafeToSafe(data);
if (extraData) {
const safeExtraData = Base64.unsafeToSafe(extraData);
return `ssb:${type}/${format}/${safeData}/${safeExtraData}`;
}
else {
return `ssb:${type}/${format}/${safeData}`;
}
const { type, format, data } = parts;
return `ssb:${type}/${format}/${Base64.unsafeToSafe(data)}`;
}

@@ -320,11 +277,8 @@ exports.compose = compose;

}
const [type, format, safeData, safeExtraData] = pathname.split('/');
const data = Base64.safeToUnsafe(safeData);
let [type, format, data] = pathname.split('/');
data = Base64.safeToUnsafe(data);
const parts = { type, format, data };
validateParts(parts);
fixParts(parts);
if (safeExtraData)
parts.extraData = Base64.safeToUnsafe(safeExtraData);
return parts;
}
exports.decompose = decompose;
{
"name": "ssb-uri2",
"version": "2.0.0",
"version": "2.0.1",
"description": "Utilities for recognizing and converting SSB URIs",

@@ -39,4 +39,3 @@ "repository": {

"coverage": "nyc npm run test"
},
"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"
}
}
}
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