Socket
Socket
Sign inDemoInstall

ssb-uri2

Package Overview
Dependencies
Maintainers
1
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.2.0 to 1.3.0

27

lib/index.d.ts
import { BlobId, FeedId, MsgId } from 'ssb-typescript';
declare type FeedTF = ['feed', 'ed25519'] | ['feed', 'bendybutt-v1'];
declare type MessageTF = ['message', 'sha256'] | ['message', 'bendybutt-v1'];
declare type BlobTF = ['blob', 'sha256'];
declare type AddressTF = ['address', 'multiserver'];
export declare function fromFeedSigil(sigil: FeedId): string;

@@ -16,2 +20,4 @@ export declare function fromMessageSigil(sigil: MsgId): string;

export declare function isAddressSSBURI(uri: string | null): boolean;
export declare function isEncryptionKeyBox2DMDiffieHellmanSSBURI(uri: string | null): boolean;
export declare function isIdentityPOBoxSSBURI(uri: string | null): boolean;
export declare function isExperimentalSSBURI(uri: string | null): boolean;

@@ -21,27 +27,24 @@ export declare function isExperimentalSSBURIWithAction(action: string): (uri: string | null) => boolean;

interface CanonicalFeedParts {
type: 'feed';
format: 'ed25519' | 'bendybutt-v1';
type: FeedTF[0];
format: FeedTF[1];
data: string;
}
interface CanonicalMessageParts {
type: 'message';
format: 'sha256' | 'bendybutt-v1';
type: MessageTF[0];
format: MessageTF[1];
data: string;
}
interface CanonicalBlobParts {
type: 'blob';
format: 'sha256';
type: BlobTF[0];
format: BlobTF[1];
data: string;
}
interface CanonicalAddressParts {
type: 'address';
format: 'multiserver';
type: AddressTF[0];
format: AddressTF[1];
data: string;
}
declare type CanonicalParts = CanonicalFeedParts | CanonicalMessageParts | CanonicalBlobParts | CanonicalAddressParts;
declare type RoughlyParts = {
[k in keyof CanonicalParts]?: string;
};
export declare function compose(parts: RoughlyParts): string;
export declare function compose(parts: Partial<CanonicalParts>): string;
export declare function decompose(uri: string): CanonicalParts;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decompose = exports.compose = exports.isSSBURI = exports.isExperimentalSSBURIWithAction = exports.isExperimentalSSBURI = exports.isAddressSSBURI = exports.isBlobSSBURI = exports.isBendyButtV1MessageSSBURI = exports.isMessageSSBURI = 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.isSSBURI = exports.isExperimentalSSBURIWithAction = exports.isExperimentalSSBURI = exports.isIdentityPOBoxSSBURI = exports.isEncryptionKeyBox2DMDiffieHellmanSSBURI = exports.isAddressSSBURI = exports.isBlobSSBURI = exports.isBendyButtV1MessageSSBURI = exports.isMessageSSBURI = exports.isBendyButtV1FeedSSBURI = exports.isFeedSSBURI = exports.toMultiserverAddress = exports.toBlobSigil = exports.toMessageSigil = exports.toFeedSigil = exports.fromMultiserverAddress = exports.fromBlobSigil = exports.fromMessageSigil = exports.fromFeedSigil = void 0;
const urlParse = require('url-parse');

@@ -13,10 +13,10 @@ const Base64 = {

};
function getSigilData(pathname) {
function extractBase64Data(pathname) {
var _a;
if (!pathname)
return null;
const ref = (_a = /(:|\/)([\w_\-=]+)$/.exec(pathname)) === null || _a === void 0 ? void 0 : _a[2];
if (!ref)
const lastPortion = (_a = /(:|\/)([\w_\-=]+)$/.exec(pathname)) === null || _a === void 0 ? void 0 : _a[2];
if (!lastPortion)
return null;
return Base64.safeToUnsafe(ref);
return Base64.safeToUnsafe(lastPortion);
}

@@ -46,6 +46,6 @@ function fromFeedSigil(sigil) {

return null;
const sigilData = getSigilData(urlParse(uri, true).pathname);
if (!sigilData)
const base64Data = extractBase64Data(urlParse(uri, true).pathname);
if (!base64Data)
return null;
return `@${sigilData}.ed25519`;
return `@${base64Data}.ed25519`;
}

@@ -56,13 +56,13 @@ exports.toFeedSigil = toFeedSigil;

return null;
const sigilData = getSigilData(urlParse(uri, true).pathname);
if (!sigilData)
const base64Data = extractBase64Data(urlParse(uri, true).pathname);
if (!base64Data)
return null;
return `%${sigilData}.sha256`;
return `%${base64Data}.sha256`;
}
exports.toMessageSigil = toMessageSigil;
function toBlobSigil(uri) {
const sigilData = getSigilData(urlParse(uri, true).pathname);
if (!sigilData)
const base64Data = extractBase64Data(urlParse(uri, true).pathname);
if (!base64Data)
return null;
return `&${sigilData}.sha256`;
return `&${base64Data}.sha256`;
}

@@ -74,45 +74,29 @@ exports.toBlobSigil = toBlobSigil;

exports.toMultiserverAddress = toMultiserverAddress;
function isFeedSSBURI(uri) {
function checkTypeFormat(uri, ...args) {
if (!uri)
return false;
return ((uri.startsWith('ssb:feed:ed25519:') ||
uri.startsWith('ssb:feed/ed25519/') ||
uri.startsWith('ssb://feed/ed25519/')) &&
!!getSigilData(urlParse(uri, true).pathname));
const [type, format] = args;
return ((uri.startsWith(`ssb:${type}:${format}:`) ||
uri.startsWith(`ssb:${type}/${format}/`) ||
uri.startsWith(`ssb://${type}/${format}/`)) &&
!!extractBase64Data(urlParse(uri, true).pathname));
}
function isFeedSSBURI(uri) {
return checkTypeFormat(uri, 'feed', 'ed25519');
}
exports.isFeedSSBURI = isFeedSSBURI;
function isBendyButtV1FeedSSBURI(uri) {
if (!uri)
return false;
return ((uri.startsWith('ssb:feed:bendybutt-v1:') ||
uri.startsWith('ssb:feed/bendybutt-v1/') ||
uri.startsWith('ssb://feed/bendybutt-v1/')) &&
!!getSigilData(urlParse(uri, true).pathname));
return checkTypeFormat(uri, 'feed', 'bendybutt-v1');
}
exports.isBendyButtV1FeedSSBURI = isBendyButtV1FeedSSBURI;
function isMessageSSBURI(uri) {
if (!uri)
return false;
return ((uri.startsWith('ssb:message:sha256:') ||
uri.startsWith('ssb:message/sha256/') ||
uri.startsWith('ssb://message/sha256/')) &&
!!getSigilData(urlParse(uri, true).pathname));
return checkTypeFormat(uri, 'message', 'sha256');
}
exports.isMessageSSBURI = isMessageSSBURI;
function isBendyButtV1MessageSSBURI(uri) {
if (!uri)
return false;
return ((uri.startsWith('ssb:message:bendybutt-v1:') ||
uri.startsWith('ssb:message/bendybutt-v1/') ||
uri.startsWith('ssb://message/bendybutt-v1/')) &&
!!getSigilData(urlParse(uri, true).pathname));
return checkTypeFormat(uri, 'message', 'bendybutt-v1');
}
exports.isBendyButtV1MessageSSBURI = isBendyButtV1MessageSSBURI;
function isBlobSSBURI(uri) {
if (!uri)
return false;
return ((uri.startsWith('ssb:blob:sha256:') ||
uri.startsWith('ssb:blob/sha256/') ||
uri.startsWith('ssb://blob/sha256/')) &&
!!getSigilData(urlParse(uri, true).pathname));
return checkTypeFormat(uri, 'blob', 'sha256');
}

@@ -130,2 +114,10 @@ exports.isBlobSSBURI = isBlobSSBURI;

exports.isAddressSSBURI = isAddressSSBURI;
function isEncryptionKeyBox2DMDiffieHellmanSSBURI(uri) {
return checkTypeFormat(uri, 'encryption-key', 'box2-dm-dh');
}
exports.isEncryptionKeyBox2DMDiffieHellmanSSBURI = isEncryptionKeyBox2DMDiffieHellmanSSBURI;
function isIdentityPOBoxSSBURI(uri) {
return checkTypeFormat(uri, 'identity', 'po-box');
}
exports.isIdentityPOBoxSSBURI = isIdentityPOBoxSSBURI;
function isExperimentalSSBURI(uri) {

@@ -132,0 +124,0 @@ if (!uri)

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

@@ -5,0 +5,0 @@ "repository": {

@@ -44,2 +44,6 @@ # ssb-uri2

### `isEncryptionKeyBox2DMDiffieHellmanSSBURI(uri: string | null): boolean`
### `isIdentityPOBoxSSBURI(uri: string | null): boolean`
### `isExperimentalSSBURI(uri: string | null): boolean`

@@ -46,0 +50,0 @@

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