
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Generate a readable hash from a dry-struct for easier manipulation
The gem is still work in progress and is not yet fully tested.
Add this line to your application's Gemfile:
gem 'dry_struct_parser'
And then execute:
bundle install
Lets say we have the following Dry::Struct definition:
class DTO1 < Dry::Struct
attribute :dto1_field, Types::String
end
class DTO2 < Dry::Struct
attribute :dto2_field, Types::String
end
class DTO < Dry::Struct
attribute :dynamic_dto, DTO1 | DTO2
end
parser = DryStructParser::StructSchemaParser.new
parser.call(DTO)
=> {
"dynamic_dto": [ # ARRAY
{
"type": "hash",
"required": true,
"nullable": false,
"keys": {
"dto1_field": {
"type": "string",
"required": true,
"nullable": false
}
}
},
{
"type": "hash",
"required": true,
"nullable": false,
"keys": {
"dto2_field": {
"type": "string",
"required": true,
"nullable": false
}
}
}
]
}
The required key depends on whether we define the field as attribute or attribute?
For more complex types, for example DTO1 | DTO2 or Types::Array.of(DTO1 | DTO2), the parser converts the field value to an array of both schemas.
You can also modify the fields by passing a block after the .call() method.
DryStructParser::StructSchemaParser.new.call(DTO) do |it|
# types = string/integer/hash/array
# Remove a field
its.keys = it.keys.except(:field_name)
# Add new field on root level
it.keys[:new_field_name] = { type: type, required: true/false, nullable: true/false }
# Add a new field in nested hash/array
it.keys[:nested_field][:keys][:new_field_name] = {
type: type, required: true/false, nullable: true/false
}
# Remove a field in nested hash/array
it.keys = it.keys[:nested_field][:keys].except(:field_name)
# Add an array or hash
it.keys[:nested_field] = {
type: "array/hash", required: true/false, nullable: true/false, keys: {
# List all nested fields
new_field: { type: :type, required: true/false, nullable: true/false }
}
}
# Add an Array of primitive types, type field needs to be the element type(string, integer, float),
and add an array: true flag
it.keys[:array_field_name] = {
type: type, array: true, required: true/false, nullable: true/false
}
end
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/Jane-Terziev/dry_struct_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the DryStructParser project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that dry_struct_parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.