Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@did-core/data-model
Advanced tools
Readme
npm i @did-core/data-model --save
import { factory, DidDocument } from '@did-core/data-model';
import { representation } from '@did-core/did-ld-json';
const didDocument: DidDocument = factory.build({
entries: {
id: 'did:example:123',
},
});
// Add support for production and consumption for the JSON-LD Representation
didDocument.addRepresentation({ 'application/did+ld+json': representation });
// JSON-LD requires `@context` and that all terms be defined by it.
try {
await didDocument.produce('application/did+ld+json');
} catch (e) {
expect(e.message).toBe('@context is required and not present.');
}
// Add `@context` to the Abstract Data Model
didDocument.assign({
'@context': 'https://www.w3.org/ns/did/v1',
});
// Produce JSON-LD
const serialization = await didDocument.produce('application/did+ld+json');
expect(JSON.parse(serialization.toString())).toEqual({
'@context': 'https://www.w3.org/ns/did/v1',
id: 'did:example:123',
});
// What about unregistered properties?
const didDocument = factory.build({
entries: {
'@context': ['https://www.w3.org/ns/did/v1'],
id: 'did:example:123',
'🔥': '💩',
},
});
didDocument.addRepresentation({ 'application/did+ld+json': representation });
// JSON-LD Production fails when `@context` does not define all properties
try {
await didDocument.produce('application/did+ld+json');
} catch (e) {
expect(e.message).toBe('@context does not define: 🔥');
}
// Add context so your DID Document works with the open world model of verifiable credentials...
didDocument.assign({
'@context': [
'https://www.w3.org/ns/did/v1',
{
'🔥': 'https://en.wikipedia.org/wiki/Open-world_assumption',
},
],
});
// Produce JSON-LD that works with Verifiable Credentials
const serialization = await didDocument.produce('application/did+ld+json');
expect(JSON.parse(serialization.toString())).toEqual({
'@context': [
'https://www.w3.org/ns/did/v1',
{
'🔥': 'https://en.wikipedia.org/wiki/Open-world_assumption',
},
],
id: 'did:example:123',
'🔥': '💩',
});
import { factory } from '@did-core/data-model';
import { representation } from '@did-core/did-dag-cbor';
const serialization = await factory
.build({ entries: { id: 'did:example:123' } })
.addRepresentation({ 'application/did+dag+cbor': representation })
.produce('application/did+dag+cbor');
expect(serialization.toString('hex')).toBe(
'a16269646f6469643a6578616d706c653a313233'
);
import { factory } from '@did-core/data-model';
import { representation } from '@did-core/did-json';
const didDocument = await factory
.build()
.addRepresentation({ 'application/did+json': representation })
.consume(
'application/did+json',
// be careful what you consume!
Buffer.from(
`{"id": "did:example:123","__proto__":{"isAdmin": "Let json be json!"}}`
)
);
const serialization = await didDocument
// be careful what you assign!
.assign({ 'this is safe': 'right guys...?' })
.produce('application/did+json');
// JSON only requires `id` be present...
expect(JSON.parse(serialization.toString())).toEqual({
id: 'did:example:123',
'this is safe': 'right guys...?',
});
// prototype pollution will succeeed if you are not careful...
// expect((didDocument.entries as any).isAdmin).toBe('Let json be json!');
FAQs
``` npm i @did-core/data-model --save ```
The npm package @did-core/data-model receives a total of 1,708 weekly downloads. As such, @did-core/data-model popularity was classified as popular.
We found that @did-core/data-model demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.