pssh-tools
Advanced tools
Comparing version 0.1.2 to 0.1.3
export * from './lib/pssh'; | ||
export * from './lib/types'; |
@@ -1,2 +0,2 @@ | ||
import { PREncodePsshRequest } from '../types'; | ||
import * as T from '../types'; | ||
interface KeyItem { | ||
@@ -6,6 +6,6 @@ kid: string; | ||
} | ||
export declare const encodePssh: (request: PREncodePsshRequest) => string; | ||
export declare const decodeData: (data: string) => import("../types").PRData | import("../types").WVData | null; | ||
export declare const encodePssh: (request: T.PlayReadyEncodeConfig) => string; | ||
export declare const decodeData: (data: string) => T.PlayReadyData | T.WidevineData | null; | ||
export declare const decodeKey: (keyData: string) => string; | ||
export declare const encodeKey: (keyData: string) => KeyItem; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
import { PsshHeaderRequest, PRData, WVData, PsshDecodeResult } from '../types'; | ||
import { HeaderConfig, PlayReadyData, WidevineData, DecodeResult } from '../types'; | ||
export declare const system: { | ||
@@ -20,4 +20,4 @@ WIDEVINE: { | ||
}; | ||
export declare const getPsshHeader: (request: PsshHeaderRequest) => string; | ||
export declare const decodePssh: (data: string) => PsshDecodeResult; | ||
export declare const decodePsshData: (targetSystem: string, data: string) => PRData | WVData | null; | ||
export declare const getPsshHeader: (request: HeaderConfig) => string; | ||
export declare const decodePssh: (data: string) => DecodeResult; | ||
export declare const decodePsshData: (targetSystem: string, data: string) => PlayReadyData | WidevineData | null; |
@@ -1,3 +0,3 @@ | ||
import { WVEncodePsshRequest } from '../types'; | ||
export declare const encodePssh: (request: WVEncodePsshRequest) => string; | ||
export declare const decodeData: (data: string) => import("../types").PRData | import("../types").WVData | null; | ||
import * as T from '../types'; | ||
export declare const encodePssh: (request: T.WidevineEncodeConfig) => string; | ||
export declare const decodeData: (data: string) => T.PlayReadyData | T.WidevineData | null; |
/// <reference types="node" /> | ||
declare type Omit<K, KEY extends keyof K> = Pick<K, Exclude<keyof K, KEY>>; | ||
export interface WVEncodePsshRequest { | ||
export interface WidevineEncodeConfig { | ||
contentId: string; | ||
@@ -11,4 +11,4 @@ dataOnly: boolean; | ||
} | ||
export declare type WVEncodePsshDataRequest = Omit<WVEncodePsshRequest, 'dataOnly'>; | ||
export interface PREncodePsshRequest { | ||
export declare type WidevineDataEncodeConfig = Omit<WidevineEncodeConfig, 'dataOnly'>; | ||
export interface PlayReadyEncodeConfig { | ||
keyIds: string[]; | ||
@@ -20,4 +20,4 @@ licenseUrl: string; | ||
} | ||
export declare type PREncodePsshDataRequest = Omit<PREncodePsshRequest, 'dataOnly'>; | ||
export interface PsshHeaderRequest { | ||
export declare type PlayReadyDataEncodeConfig = Omit<PlayReadyEncodeConfig, 'dataOnly'>; | ||
export interface HeaderConfig { | ||
systemId: string; | ||
@@ -27,3 +27,3 @@ keyIds: string[]; | ||
} | ||
export interface PRData { | ||
export interface PlayReadyData { | ||
recordSize: number; | ||
@@ -33,3 +33,3 @@ recordType: number; | ||
} | ||
export interface WVData { | ||
export interface WidevineData { | ||
widevineKeyCount?: number; | ||
@@ -40,4 +40,4 @@ keyId?: string[]; | ||
} | ||
export declare type PsshData = PRData | WVData; | ||
export interface PsshDecodeResult { | ||
export declare type PsshData = PlayReadyData | WidevineData; | ||
export interface DecodeResult { | ||
keyIds?: string[]; | ||
@@ -44,0 +44,0 @@ dataObject?: PsshData; |
{ | ||
"name": "pssh-tools", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Tools to generate PSSH Data and PSSH Box", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
export * from './lib/pssh' | ||
export * from './lib/types' |
import * as crypto from 'crypto' | ||
import * as tools from './tools' | ||
import { PREncodePsshDataRequest, PREncodePsshRequest, PsshHeaderRequest } from '../types'; | ||
import * as T from '../types' | ||
@@ -127,3 +127,3 @@ const DRM_AES_KEYSIZE_128 = 16 | ||
const getPsshData = (request: PREncodePsshDataRequest): string => { | ||
const getPsshData = (request: T.PlayReadyDataEncodeConfig): string => { | ||
const xmlData = request.compatibilityMode === true ? constructProXML4(request.keyIds[0], request.licenseUrl, request.keySeed) : constructProXML(request.keyIds, request.licenseUrl, request.keySeed) | ||
@@ -150,6 +150,6 @@ | ||
const getPsshBox = (request: PREncodePsshDataRequest) => { | ||
const getPsshBox = (request: T.PlayReadyDataEncodeConfig) => { | ||
// data | ||
const data = getPsshData(request) | ||
const requestData: PsshHeaderRequest = { | ||
const requestData: T.HeaderConfig = { | ||
systemId: tools.system.PLAYREADY.id, | ||
@@ -163,3 +163,3 @@ keyIds: request.keyIds, | ||
export const encodePssh = (request: PREncodePsshRequest) => { | ||
export const encodePssh = (request: T.PlayReadyEncodeConfig) => { | ||
if (request.dataOnly) { | ||
@@ -166,0 +166,0 @@ return getPsshData(request) |
import * as path from 'path' | ||
import * as protobuf from 'protobufjs' | ||
import { PsshHeaderRequest, PRData, WVData, PsshDecodeResult, PsshData } from '../types'; | ||
import { HeaderConfig, PlayReadyData, WidevineData, DecodeResult, PsshData } from '../types'; | ||
@@ -40,3 +40,3 @@ export const system = { | ||
export const getPsshHeader = (request: PsshHeaderRequest): string => { | ||
export const getPsshHeader = (request: HeaderConfig): string => { | ||
const pssh = [] | ||
@@ -95,3 +95,3 @@ | ||
export const decodePssh = (data: string) => { | ||
const result: PsshDecodeResult = {} | ||
const result: DecodeResult = {} | ||
const decodedData = Buffer.from(data, 'base64') | ||
@@ -196,3 +196,3 @@ | ||
if (systemName === system.WIDEVINE.name && result.dataObject) { | ||
let dataObject: WVData = result.dataObject as WVData | ||
let dataObject: WidevineData = result.dataObject as WidevineData | ||
if (dataObject.keyId) { | ||
@@ -215,3 +215,3 @@ psshArray.push(` Key IDs (${dataObject.keyId.length})`) | ||
if (systemName === system.PLAYREADY.name && result.dataObject) { | ||
let dataObject: PRData = result.dataObject as PRData | ||
let dataObject: PlayReadyData = result.dataObject as PlayReadyData | ||
psshArray.push(` Record size(${dataObject.recordSize})`) | ||
@@ -243,6 +243,6 @@ if (dataObject.recordType) { | ||
const decodeWVData = (psshData: Buffer): WVData => { | ||
const decodeWVData = (psshData: Buffer): WidevineData => { | ||
// cenc header | ||
let header = decodeWidevineHeader(psshData) | ||
let wvData: WVData = {} | ||
let wvData: WidevineData = {} | ||
@@ -265,3 +265,3 @@ if (header.keyId && header.keyId.length > 0) { | ||
const decodePRData = (psshData: Buffer): PRData => { | ||
const decodePRData = (psshData: Buffer): PlayReadyData => { | ||
// pro header | ||
@@ -268,0 +268,0 @@ let proHeader = Buffer.alloc(10) |
import * as path from 'path' | ||
import * as protobuf from 'protobufjs' | ||
import { WVEncodePsshRequest, WVEncodePsshDataRequest, PsshHeaderRequest } from '../types'; | ||
import * as T from '../types'; | ||
@@ -16,3 +16,3 @@ import * as tools from './tools' | ||
const getPsshData = (request: WVEncodePsshDataRequest) => { | ||
const getPsshData = (request: T.WidevineDataEncodeConfig) => { | ||
const protoFile = path.join(__dirname, 'proto', 'WidevineCencHeader.proto') | ||
@@ -55,6 +55,6 @@ const root = protobuf.loadSync(protoFile) | ||
const getPsshBox = (request: WVEncodePsshDataRequest) => { | ||
const getPsshBox = (request: T.WidevineDataEncodeConfig) => { | ||
// data | ||
const data = getPsshData(request) | ||
const requestData: PsshHeaderRequest = { | ||
const requestData: T.HeaderConfig = { | ||
systemId: tools.system.WIDEVINE.id, | ||
@@ -68,3 +68,3 @@ keyIds: request.keyIds, | ||
export const encodePssh = (request: WVEncodePsshRequest) => { | ||
export const encodePssh = (request: T.WidevineEncodeConfig) => { | ||
if (request.dataOnly) { | ||
@@ -71,0 +71,0 @@ return getPsshData(request) |
type Omit<K, KEY extends keyof K> = Pick<K, Exclude<keyof K, KEY>> | ||
export interface WVEncodePsshRequest { | ||
export interface WidevineEncodeConfig { | ||
contentId: string | ||
@@ -12,5 +12,5 @@ dataOnly: boolean | ||
export type WVEncodePsshDataRequest = Omit<WVEncodePsshRequest, 'dataOnly'> | ||
export type WidevineDataEncodeConfig = Omit<WidevineEncodeConfig, 'dataOnly'> | ||
export interface PREncodePsshRequest { | ||
export interface PlayReadyEncodeConfig { | ||
keyIds: string[] | ||
@@ -23,5 +23,5 @@ licenseUrl: string | ||
export type PREncodePsshDataRequest = Omit<PREncodePsshRequest, 'dataOnly'> | ||
export type PlayReadyDataEncodeConfig = Omit<PlayReadyEncodeConfig, 'dataOnly'> | ||
export interface PsshHeaderRequest { | ||
export interface HeaderConfig { | ||
systemId: string | ||
@@ -32,3 +32,3 @@ keyIds: string[] | ||
export interface PRData { | ||
export interface PlayReadyData { | ||
recordSize: number | ||
@@ -39,3 +39,3 @@ recordType: number | ||
export interface WVData { | ||
export interface WidevineData { | ||
widevineKeyCount?: number | ||
@@ -47,5 +47,5 @@ keyId?: string[] | ||
export type PsshData = PRData | WVData | ||
export type PsshData = PlayReadyData | WidevineData | ||
export interface PsshDecodeResult { | ||
export interface DecodeResult { | ||
keyIds?: string[] | ||
@@ -52,0 +52,0 @@ dataObject?: PsshData |
import test from 'ava' | ||
import * as pssh from '../src/index' | ||
import { WVEncodePsshRequest, PREncodePsshRequest, PRData } from '../src/lib/types'; | ||
import { WidevineEncodeConfig, PlayReadyEncodeConfig, PlayReadyData } from '../src/lib/types'; | ||
@@ -12,3 +12,3 @@ const KID = '0123456789abcdef0123456789abcdef' | ||
test('Should return Widevine PSSH version 0 without KID', t => { | ||
const payload: WVEncodePsshRequest = { contentId: 'cenc-content-id', trackType: 'HD', provider: 'widevine_test', keyIds: [], protectionScheme: 'cenc', dataOnly: false } | ||
const payload: WidevineEncodeConfig = { contentId: 'cenc-content-id', trackType: 'HD', provider: 'widevine_test', keyIds: [], protectionScheme: 'cenc', dataOnly: false } | ||
@@ -23,3 +23,3 @@ const data = pssh.widevine.encodePssh(payload) | ||
test('Should return Widevine PSSH version 0 with KIDs', t => { | ||
const payload: WVEncodePsshRequest = { contentId: 'cenc-content-id', trackType: 'HD', keyIds: [KID], provider: 'widevine_test', protectionScheme: 'cenc', dataOnly: false } | ||
const payload: WidevineEncodeConfig = { contentId: 'cenc-content-id', trackType: 'HD', keyIds: [KID], provider: 'widevine_test', protectionScheme: 'cenc', dataOnly: false } | ||
@@ -38,3 +38,3 @@ const data = pssh.widevine.encodePssh(payload) | ||
test('Should return PlayReady PSSH version 1 with KID', t => { | ||
const payload: PREncodePsshRequest = { keyIds: [KID], licenseUrl: LA_URL, keySeed: '', compatibilityMode: false, dataOnly: false } | ||
const payload: PlayReadyEncodeConfig = { keyIds: [KID], licenseUrl: LA_URL, keySeed: '', compatibilityMode: false, dataOnly: false } | ||
@@ -53,3 +53,3 @@ const data = pssh.playready.encodePssh(payload) | ||
test('Should return PlayReady PSSH version 1 with Header Version 4.0.0.0 and KID', t => { | ||
const payload: PREncodePsshRequest = { keyIds: [KID], licenseUrl: LA_URL, keySeed: '', compatibilityMode: true, dataOnly: false } | ||
const payload: PlayReadyEncodeConfig = { keyIds: [KID], licenseUrl: LA_URL, keySeed: '', compatibilityMode: true, dataOnly: false } | ||
@@ -78,3 +78,3 @@ const data = pssh.playready.encodePssh(payload) | ||
test('Should be able to decode PlayReady PSSH data', t => { | ||
const result: PRData = pssh.playready.decodeData(PSSH_DATA_PR) as PRData | ||
const result: PlayReadyData = pssh.playready.decodeData(PSSH_DATA_PR) as PlayReadyData | ||
if (result && result.recordXml && result.recordSize) { | ||
@@ -81,0 +81,0 @@ console.log('PR Data:', result.recordXml) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78734
1295